如何强制 VC++名称修改 C++Builder?
是否可以从 C++Builder DLL 中导出具有特定名称的函数?
我正在尝试构建一个 C++Builder DLL 来替换现有的 VC++ DLL。问题是使用 DLL 的应用程序期望其中一个函数具有特定的损坏名称。
也就是说,它期望调用该函数:
"?_FUNCTIONNAME_@@YAHPAU_PARAM1_@@PAU_PARAM2_@@@Z"
当然,我可以使用损坏的名称从 DLL 导出函数,但 CodeGear 坚持使用自己的名称损坏方案。
是否可以强制 C++Builder:
为函数使用特定的损坏名称?
或
对特定函数使用 VC++ 名称修饰?
请注意,我只想更改特定函数的重整,而不是 DLL 中的所有函数。
Is it possible to export a function from a C++Builder DLL with a specific mangled name?
I am trying to build a C++Builder DLL to replace an existing VC++
DLL. The problem is that the application that uses the DLL expects one of the functions to have a specific mangled name.
That is, it expects the function to be called:
"?_FUNCTIONNAME_@@YAHPAU_PARAM1_@@PAU_PARAM2_@@@Z"
Of course I can export function from my DLL with a mangled name but CodeGear insists on using its own name mangling scheme.
Is it possible to force C++Builder to:
Use a specific mangled name for a function?
or
Use VC++ name mangling for a specific function?
Note that I only want to change the mangling for a specific function, not all the functions in the DLL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
名称修改只是 ABI 的众多方面之一。事实上,它会更容易标准化。编译器在使用不同的 ABI 时会故意使用不同的名称修饰,以防止链接不兼容的对象。
对于给定函数,您可以尝试的一件事是将其标记为
extern "C"
,然后它将使用 C 的调用约定和相同的修饰(通常根本没有修饰或只是一个初始的_
)。显然这不会解决其他问题(异常处理、vtbls的精确内容、哪些寄存器用于传递参数、标准库的精确定义……)Name mangling is just one of many aspects of the ABI. And it fact it would be the more easy to standardize. Compilers are using purposefully different name manglings when they are using different ABI in order to prevent linking incompatible objects.
One thing you may try for a given function is to mark it
extern "C"
, then it will use the calling convention of C and the same mangling (commonly no mangling at all or just an initial_
). Obviously that won't take care of other issues (handling of exceptions, precise content of vtbls, which registers are used for passing parameters, the precise definition of the standard library, ...)使用
.def
文件为导出的函数指定您自己的命名。Use a
.def
file to specify your own naming for the exported function.