I am trying to execute a callback-routine via DLL, where I am passing the address of the callback-routine as parameter. The parameter is arriving at the DLL correctly, but when calling it (via Inline-Assembler-function CALL) I always get "Invalid Memory Access".
Does anyone have an idea what's wrong here, isn't CALL the correct function?
Thanks,
sepp
mydll.pb
Code: Select all
Declare ErrorHandler()
ProcedureDLL test(*address)
; Acticate Error Handler
OnErrorCall(@ErrorHandler())
; Debugging-Messages
MessageRequester("DLL", ProgramFilename() + #CRLF$ + FormatDate("%yyyy/%mm/%dd, %hh:%ii:%ss", #PB_Compiler_Date ), 0)
MessageRequester("DLL", "Executing Address: 0x" + Hex(*address), 0)
; Execute Callback-Function
EnableASM
CALL *address
DisableASM
; Debugging-Message
MessageRequester("DLL", "Execution finished!", 0)
EndProcedure
Procedure ErrorHandler()
MessageRequester("DLL-Error", ErrorMessage())
EndProcedure
; IDE Options = PureBasic 4.61 (Windows - x86)
; ExecutableFormat = Shared Dll
; CursorPosition = 22
; Folding = -
; EnableOnError
; Executable = mydll.dll
; CPU = 1
; DisableDebugger
Code: Select all
Declare mainfunction()
; Debugging-Message
MessageRequester("Main", ProgramFilename() + #CRLF$ + FormatDate("%yyyy/%mm/%dd, %hh:%ii:%ss", #PB_Compiler_Date ), 0)
; Call DLL-Function
If OpenLibrary(0, "mydll.dll")
MessageRequester("Main", "Callback-Address: 0x" + Hex(@mainfunction), 0)
CallFunction(0, "test", @mainfunction)
CloseLibrary(0)
EndIf
; Callback-Function which should be called from DLL
Procedure mainfunction()
MessageRequester("Main", "It worked!", 0)
EndProcedure
; IDE Options = PureBasic 4.61 (Windows - x86)
; CursorPosition = 7
; Folding = -
; EnableUnicode
; Executable = dllcaller.exe
; CPU = 1
; DisableDebugger