It's time for stdCallback to get a refactor. I feel some aspects are overcomplicated and this is in part because I didn't really know what I was doing when I originally made it.
Structure:
Private Enum CallbackType
EApplicationRun
ECallByName
EDispCallFunc
End Enum
Private Type TThis
iType as CallbackType
args() as variant
vBoundArgs as variant
End Type
Private This as TThis
'Core constructors
Public Function CreateFromRunCommand(ByVal sRunCommand as string) as stdCallback
set CreateFromRunCommand = new stdCallback
CreateFromRunCommand.protInit(CallbackType.EApplicationRun, Array(sRunCommand))
End Function
Public Function CreateFromObjectMember(Byval o as object, ByVal sMemberName as string, ByVal cType as vbCallType) as stdCallback
set CreateFromObjectMember= new stdCallback
CreateFromObjectMember.protInit(CallbackType.ECallByName, Array(o, sMemberName, cType))
End Function
Public Function CreateFromObjectOffset(ByVal oPtr as LongPtr, ByVal iVTableOffset as LongPtr, ByVal iRetType as vbVarType, ByRef vParamTypes() as vbVarType)
set CreateFromObjectOffset = new stdCallback
CreateFromObjectOffset.protInit(CallbackType.EDispCallFunc, Array(oPtr, iVTableOffset, iRetType, vParamTypes))
End Function
Public Function Clone() as stdCallback
set Clone = new stdCallback
Clone.protInit(This.iType, This.args)
End Function
Public Function Bind(ParamArray vParams()) as stdCallback
set Bind = Clone()
Bind.protBindParams(vParams)
End Function
'More specific constructors
Public Function CreateFromModule(sModuleName as string, sMethodName as string)
set CreateFromModule = CreateFromRunCommand(sModuleName & "." & sMethodName)
End Function
Public Function CreateFromWorkbookModule(sWorkbookPath as string, sModuleName as string, sMethodName as string)
set CreateFromWorkbookModule = CreateFromRunCommand("'" & sWorkbookPath & "'!" & sModuleName & "." & sMethodName)
End Function
Public Function CreateFromObjectMethod(ByVal o as object, ByVal sMethodName as string)
set CreateFromObjectMethod = CreateFromObjectMember(o, sMethodName, vbMethod
End Function
Public Function CreateFromObjectProperty(ByVal o as object, ByVal sPropertyName as string, ByVal cType as vbCallType)
set CreateFromObjectProperty = CreateFromObjectMember(o, sPropertyName, cType)
End Function
Public Function CreateFromFunctionPointer(ByVal iPtr as LongPtr, ByVal iRetType as vbVarType, ByRef vParamTypes() as vbVarType)
set CreateFromFunctionPointer = CreateFromObjectOffset(NULL_PTR, iPtr, iRetType, vParamTypes)
End Function
'@protected
Friend Sub protInit(ByVal iType as Long, vArgs() as variant)
This.iType = iType
This.args = vArgs
This.vBoundArgs = Null
End Sub
It's time for
stdCallback
to get a refactor. I feel some aspects are overcomplicated and this is in part because I didn't really know what I was doing when I originally made it.Structure: