1. Win32 callbacks
This might be a question to Rob but maybe someone
else has the answer or is interested on the subject.
I'm trying to do some DLL's to extend (greatly) Euphoria
functionality. I'm coding this stuff on Delphi (version 3).
Everything is fine when my Eu program calls the DLL. I
need the DLL to callback one function on the Eu program
(event handlers). I use something like:
[on exw program]
<link dll ... etc>
integer cb
procedure callback -- Our callback procedure
<do something>
return --(*)
end procedure
SomeDllProcedure(cb) -- Call dll procedure to test our
-- callback
[on dll code (delphi)]
type
CallBackProcedure : procedure; stdcall;
<other declarations...>
var
MyCallBack : CallBackProcedure;
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:
Application error: test.exe (or exw.exe if unbouded)
The instruction at 00580354 referenced memory at bffffffff
The memory could not be written.
Click Ok.... blah, blah, blah.
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. So the question is: Is this an Euphoria limitation
or a Delphi one? Has anyone got this problem with other
laguages (C/C++?)?
Regards,
Daniel Berstein
daber at pair.com
2. 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/
3. Re: Win32 callbacks
- Posted by Daniel Berstein <daber at PAIR.COM>
Oct 25, 1998
-
Last edited Oct 26, 1998
>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.
Je, je,je ;)
>LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg,
>WPARAM wParam, LPARAM lParam)
BTW How do I get the application instance? EXW.EXE WinMain
function get's this handle from Windows. It would be useful to be able
to get this handle. I notice you handcoded 0 in window.exw.
>I believe these are all 4-byte quantities. You had better add
>4 arguments to your call, otherwise the stack will get messed up.
>I *think* it should be __stdcall. I think that's what CALLBACK is defined
>as. pascal might be the same as __stdcall.
In Delphi (Object Pascal) you don't need the __, just put stdcall.
Thanks alot Rob.
Expect some cool things soon....
Regards,
Daniel Berstein
daber at pair.com
4. Re: Win32 callbacks
- Posted by Robert Craig <rds at EMAIL.MSN.COM>
Oct 26, 1998
-
Last edited Oct 27, 1998
Daniel Berstein writes:
> BTW How do I get the application instance? EXW.EXE WinMain
> function get's this handle from Windows. It would be useful to be able
> to get this handle. I notice you handcoded 0 in window.exw.
It will be available in the next release.
Other people have asked for that as well.
It's one of the parameters passed to any Windows program,
e.g. exw.exe.
Regards,
Rob Craig
Rapid Deployment Software
http://members.aol.com/FilesEu/