[fpc-pascal] windows.GetProcAddress() vs DynLibs.GetProcAddress()
Ewald
ewald at yellowcouch.org
Fri Jan 17 21:53:02 CET 2014
On 17 Jan 2014, at 21:14, Fred van Stappen wrote:
> >Ha, then you use/compiled a different version. Since a `extern "C"` preserves
> > the symbol name (that is the trick I use to link in a lot of external C++ code:
> >just put extern "C" in front of the symbol). or it could be that I am completely
> >missing something here. [for example: is the symbol `DLL_EXPORTS` defined at compile time?]
>
> Hum, "just put extern "C" in front of the symbol" (no capito ;-( )
What I'm trying to say is that if there is `extern "C"` in front of a symbol, C++ won't mangle the name. In the cpp file you attached in one of your previous mails, [assuming a C++ compiler] this is the case as per the expansion of the macro `SOUNDTOUCHDLL_API`; on one condition: that `DLL_EXPORTS` is defined.
[hint: read ahead to the second part first as it might just solve your problem]
Since you see mangled names, there must be an error or version mismatch somewhere in your build of the library. So I thought that perhaps you are using a compiled version of the library that still uses stdcall instead of cdecl.
To get closer to the bug, try the following:
- Compile with debug symbols everwhere (there is no such thing as overkill ;-) )
- Run your program in gdb and get a backtrace (`bt` on the command line of gdb), if the crash occurs at the end of the function in the library, or just after the call, then it might be a calling convention issue. If I am informed correctly (see http://stackoverflow.com/questions/3404372/stdcall-and-cdecl) then the difference between stdcall and cdecl lies in who cleans up the stack. A mismatch results in the stack being cleaned up twice or not at all. Both rather inconvenient to normal program flow. If this is the case, try changing calling conventions.
>
> PS2 : We gonna get it, im sure...
[The Second Part -->] Well, it seems I have found something interresting here (as already suggested by Marco); you don't define THandle in your library wrapper. THandle is defined as a longint (http://www.freepascal.org/docs-html/rtl/system/thandle.html), but you need a pointer.
Try putting `Type THandle = pointer;` somewhere before the first usage of this type in your library wrapper.
--
Ewald
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140117/01ae47d2/attachment.html>
More information about the fpc-pascal
mailing list