Calling D from C++
Johann MacDonagh
johann.macdonagh.no at spam.gmail.com
Mon Jul 18 20:26:40 PDT 2011
On 7/18/2011 10:40 PM, Andrej Mitrovic wrote:
> You have several problems.
>
> extern(C++) only specifies the calling convention, not the visibility
> of the symbol. To export the symbol, list it in a .def file or mark
> the function with export in the module itself, ala:
>
> export extern(C++) void SetInt(int * foo) {}
If you export it like this, it will be exported as the C++ mangled name.
If you have extern(C) it will be cdecl "_SetInt" and extern(Windows)
will be stdcall "_SetInt at 4".
> I don't know why, but if you use a .def file instead of `export` the
> function will be exported as a C function with no name mangling.
If you look at dumpbin /exports you'll see something like this:
ordinal hint RVA name
1 0 0000306C SetInt = ?SetInt@@YAXPAH at Z (void __cdecl
SetInt(int *))
So the symbol still has C++ name mangling but its exported as whatever
name you want.
More information about the Digitalmars-d-learn
mailing list