开发者

Exported function symbol name mangling

I have a D DLL that is being loaded by a C++ program that I have no control over. The program LoadLibrarys my DLL and uses GetProcAddress to find a function named "extension_load" that takes one argument (a pointer). In my D DLL I have:

extern (C) int extension_load(void* ptr) {
    return 0;
}

And this name needs to be exported 开发者_如何学Cas extension_load but it is being exported as extension_load@4, so GetProcAddress cannot find it. How do I make it plain extension_load without the name mangling?


You'll need to provide the linker with a .def file that renames the export. Docs are here, you need EXPORTS.


I got it working with some help from Hans Passant's link. Here is my .def file for anyone who will need it in the future (probably myself too):

EXETYPE NT

EXPORTS
    extension_load
    DllMain

The .def file I have is named dll.def. I have the function written as:

extern (C++) int extension_load(void* ptr) {

and the IDE I use is D-IDE, so to give the linker the def file, go to Project > Properties > Build Options and type

nameofdef.def

in the Extra Linking arguments text box. This assumes that the nameofdef.def file exists in your main project directory for D-IDE to find.


There is really no need for a def file. Just prepend your functions with export, e.g.:

    export extern (C) int extension_load(void* ptr) {
    return 0;
}

And compile via: dmd -ofmydll.dll mydll.d. Of course you'll need to define DllMain() as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜