为了避免 C++ 代码的名称重整问题,我在头文件中使用了 extern "C"。但是,问题仍然存在“当我使用 Borland C++ IDE 构建我的 dll 文件时”。
下面是我的示例代码。
其他.h文件
#define H_EXPORT WINAPI
#ifdef __cplusplus
extern "C" {
#endif
long H_EXPORT RegOpenKeyEx32( DWORD hKey,LPCSTR lpSubKey,DWORD ulOptions,REGSAM samDesired,DWORD FAR *phkResult);
#ifdef __cplusplus
}
#endif
其他.cpp文件
#define C_EXPORT WINAPI _export
//The function has been define like this
long C_EXPORT RegOpenKeyEx32( HKEY hKey,
LPCSTR lpSubKey,
DWORD ulOptions,
REGSAM samDesired,
PHKEY phkResult)
{
//some code
}
在 def 文件中为该函数给出的序数值是
RegOpenKeyEx32 @243
但是,在构建 dll 之后,我使用 Dll Export Viewer 公开了 dll,它的序数值更改为 85,函数名称更改为 @RegOpenKeyEx32$qqsp6HKEY__pxcululpp6HKEY__ 并且函数被像这样破坏 p>
在同一个文件中,即 others.cpp 只有一些函数名(5 个函数名)被破坏,其余函数名相同(没有被破坏)。我不明白这是什么问题?
知道是什么问题请回复...
最佳答案
声明和定义都必须使用 extern "C"
。
您可以修改Others.cpp文件如下
#define C_EXPORT WINAPI _export
#ifdef __cplusplus
extern "C" {
#endif
long C_EXPORT RegOpenKeyEx32(HKEY hKey,
LPCSTR lpSubKey,
DWORD ulOptions,
REGSAM samDesired,
PHKEY phkResult)
{
//some code
}
#ifdef __cplusplus
} // extern "C"
#endif
关于c++ - 即使在使用 extern "C"之后,如何解决名称重整出现的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21695200/