Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdCallback refactor #74

Open
sancarn opened this issue May 28, 2023 · 1 comment
Open

stdCallback refactor #74

sancarn opened this issue May 28, 2023 · 1 comment
Labels
enhancement New feature or request lib-stdCallback

Comments

@sancarn
Copy link
Owner

sancarn commented May 28, 2023

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
@sancarn
Copy link
Owner Author

sancarn commented Aug 5, 2023

Inclusion:

Increase performance of stdCallback.Run.

Especially for CreateFromMember() - Instead of CallByName use calls to IDispatch directly. Store DISPID for quick execution.

@sancarn sancarn added enhancement New feature or request lib-stdCallback labels Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lib-stdCallback
Projects
Status: HOLD
Development

No branches or pull requests

1 participant