creating dll to link with delphi program
Tobias Burnus
burnus@net-b.de
Tue Nov 15 10:40:00 GMT 2011
Dear Brad,
On 10/24/2011 09:00 PM, Brad Finney wrote:
>> The leading _ is added there because the ABI (application binary
>> interface) of 32bit Windows *requires* it. If you don't like it, blame
>> Microsoft.
There seems to be an additional detail, which I had overlooked: For
symbols in DLLs, there seem to be different rules. - And Delphi seems to
have use some extra convention in addition.
To quote Danny: "DLLs built with MS-Windows tools use different default
rules for the naming of __stdcall function names in export table: for
stdcall symbols the string in the dll's export table has the assembler
prefix '_' prepended, while for cdecl symbols or variable names, the
underscore prefix is stripped. In contrast, in dlls built with GNU
tools, the assembler underscore prefix is stripped from all symbols by
default."
From: http://cygwin.com/ml/binutils/2006-03/msg00086.html
Searching different webpages, I have not really found a really helpful
explanation or rules. When generating a DLL, one can (cf. link above)
modify the mangling either by flags or by the .def file.
For interaction with DLLs, you might also want to use
DLLEXPORT/DLLIMPORT, though those do not seem to change the mangling.
(dllimport of "foo" imports __imp__foo (cdecl) or __imp__foo@0
(stdcall); dllexport has _foo and _foo@0). Though, as written, when
linking one can modify the mangling by the dlltools/linker.
In any case, "underscore DLL prefix" (and variants) will turn up
hundreds of web pages, where people have similar issues - independent of
the compiler.
See also:
http://mirrors.zoreil.com/webclub.kcom.ne.jp/ma/colinp/win32/dll/make.html
and http://www.willus.com/mingw/yongweiwu_stdcall.html
Tobias,
who is rather confused and praises the Win64 and Unix (default) calling
conventions.
More information about the Fortran
mailing list