导出的函数符号名称修改
我有一个 D DLL,它正在由我无法控制的 C++ 程序加载。程序 LoadLibrarys 我的 DLL 并使用 GetProcAddress 查找名为“extension_load”的函数,该函数采用一个参数(指针)。在我的 D DLL 中,我有:
extern (C) int extension_load(void* ptr) {
return 0;
}
这个名称需要导出为extension_load,但它正在导出为extension_load@4,所以 GetProcAddress 找不到它。如何使其成为普通的 extension_load 而不需要名称修改?
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 as 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要向链接器提供重命名导出的 .def 文件。文档在这里,您需要导出。
You'll need to provide the linker with a .def file that renames the export. Docs are here, you need EXPORTS.
我在汉斯·帕桑特链接的帮助下得到了它。这是我的 .def 文件,供将来需要它的任何人(也可能是我自己)使用:
我的 .def 文件名为 dll.def。我的函数写为:
并且我使用的IDE是D-IDE,因此要给链接器提供def文件,请转到Project> >属性>构建选项并
在额外链接参数文本框中键入。这假设 nameofdef.def 文件存在于您的主项目目录中以供 D-IDE 查找。
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):
The .def file I have is named dll.def. I have the function written as:
and the IDE I use is D-IDE, so to give the linker the def file, go to Project > Properties > Build Options and type
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.
确实不需要 def 文件。只需在您的函数前面添加
export
,例如:并通过:
dmd -ofmydll.dll mydll.d
进行编译。当然,您还需要定义DllMain()
。There is really no need for a def file. Just prepend your functions with
export
, e.g.:And compile via:
dmd -ofmydll.dll mydll.d
. Of course you'll need to defineDllMain()
as well.