Lisp HUG Maillist Archive

LW doesn't find functions defined with __stdcall

Hi!

This question probably shows my complete ignorance of Win32/C/linker
issues but here goes:

I'm trying to use the pre-compiled GD library which is available at
<http://www.boutell.com/gd/http/gdwin32.zip> from LW. The problem is
that the functions in this library are declared as __stdcall and
LispWorks' FLI doesn't find them - I get messages like "trying to call
to unresolved external function..."

If I look at the exported symbols of this DLL with a tool like PE
Explorer from <http://www.heaventools.com/> I see function names like
"gdImageArc@32" instead of "gdImageArc." This is in compliance with
the documentation about calling conventions and "decorated names" that
comes with Visual Studio.

Now I had expected that LW would be able to resolve these decorated
names but it seems it isn't. It also doesn't help if I use the
decorated name instead of the plain name with
DEFINE-FOREIGN-FUNCTION. And changing the keyword argument
:CALLING-CONVENTION also doesn't make a difference. Hmmm....

Is there a way to interface with this DLL from LispWorks?

Thanks,
Edi.


Re: LW doesn't find functions defined with __stdcall

> This question probably shows my complete ignorance of Win32/C/linker
> issues but here goes:
>
> I'm trying to use the pre-compiled GD library which is available at
> <http://www.boutell.com/gd/http/gdwin32.zip> from LW. The problem is
> that the functions in this library are declared as __stdcall and
> LispWorks' FLI doesn't find them - I get messages like "trying to call
> to unresolved external function..."
>
> If I look at the exported symbols of this DLL with a tool like PE
> Explorer from <http://www.heaventools.com/> I see function names like
> "gdImageArc@32" instead of "gdImageArc." This is in compliance with
> the documentation about calling conventions and "decorated names" that
> comes with Visual Studio.
>
> Now I had expected that LW would be able to resolve these decorated
> names but it seems it isn't. It also doesn't help if I use the
> decorated name instead of the plain name with
> DEFINE-FOREIGN-FUNCTION. And changing the keyword argument
> :CALLING-CONVENTION also doesn't make a difference. Hmmm....

Changing the name would not be enough anyway.

> Is there a way to interface with this DLL from LispWorks?

I don't have problems with the API functions which use __stdcall:

(fli:define-foreign-function (%play-sound% "PlaySoundA")
    ((lpfilename :pchar) (hmod :ulong) (flags :ulong))
 :language :c
 :calling-convention :stdcall
 :result-type (:boolean :long)
 :module "winmm.dll")

Is OK.

The @32 is probably more du to the C++ name mangling.

If you don't find any better solution you can make a stub DLL where you put
your definitions in an extern "C" block and call the C++ ones from there.

Marc
..



Updated at: 2020-12-10 08:54 UTC