Re: Win32 callbacks
Daniel Berstein writes:
> SomeDllProcedure (cb: pointer); sdtcall;
> begin
> MyCallBack := cb; {Asign callback address}
> MyCallBack; {Call callback procedure}
> end;
> The DLL does call and execute the Euphoria code, but when
> we reach the return statement (*) I get a Windows error like...
Wow, you're really out there on the leading edge of technology.
I'm impressed that you were able to call the Euphoria routine at all.
Your call "MyCallBack" passes 0 arguments.
That would be a problem. The Euphoria call-back routine
must be supplied with 4 arguments. The way it works, there's
a C function in the Euphoria interpreter that actually receives
the call-back (normally coming from Windows). It accepts 4 arguments,
and does the necessary conversion of arguments from C to
Euphoria data types before calling your Euphoria "call-back" routine
written in Euphoria. The C routine in the interpreter is declared
as:
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
I believe these are all 4-byte quantities. You had better add
4 arguments to your call, otherwise the stack will get messed up.
You could simply pass (0,0,0,0). In Euphoria v2.0 your
call-back routine must be a function taking 4 arguments, and there
is only one call-back routine (maximum) allowed in a program.
> I tracked the bug in between Euphoria returns the control to
> the DLL and the DLL getting the control from Euphoria. I
> supposed it had something to do with calling conventions,
> but tried all (register, pascal, cdecl, stdcall, safecall) with the
> same result.
I *think* it should be __stdcall. I think that's what CALLBACK is defined
as. pascal might be the same as __stdcall.
I know that if I pass the wrong number of args to a C .DLL routine,
I usually get a crash, sort of like what you had.
Regards,
Rob Craig
Rapid Deployment Software
http://members.aol.com/FilesEu/
|
Not Categorized, Please Help
|
|