GetProcAddress 不适用于 void 以外的函数
我在 GetProcAddress 方面遇到问题: 我编写了一个简单的 DLL,其中只有一个函数:
extern "C" LRESULT WINAPI Function(HWND Hwnd, UINT Message,
WPARAM wParam, LPARAM lParam)
{
Beep(1000, 1000);
return CallNextHookEx(0, Message, wParam, lParam);
}
当我尝试获取函数的地址时,GetProcAddress 失败,错误代码为 127 (ERROR_PROC_NOT_FOUND)。但是,如果我使用 void 作为函数类型,它就可以完美工作。我真的不明白为什么它会这样。任何建议将不胜感激!
顺便说一句:DependencyWalker 显示该函数的名称确实是“Function”,没有应用任何更改。
I have a problem with GetProcAddress:
I wrote a simple DLL with just one function in it:
extern "C" LRESULT WINAPI Function(HWND Hwnd, UINT Message,
WPARAM wParam, LPARAM lParam)
{
Beep(1000, 1000);
return CallNextHookEx(0, Message, wParam, lParam);
}
When I try to get function's address GetProcAddress fails with the ErrorCode 127 (ERROR_PROC_NOT_FOUND). However, if I use void as the function type it works perfectly. I can't really figure out why it behaves like this. Any suggestions would be greatly appreciated!
BTW: DependencyWalker shows that the function's name is indeed "Function" no changes have been applied.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GetProcAddress 只有两种失败模式:
该函数的导出命名不是“Function”,除非您使用 .def 文件重命名导出或创建 64位 DLL。对于 32 位版本,它将是“_Function@16”。 @16 后缀与您无法使其适用于具有任何参数的函数这一事实密切相关。
从 Visual Studio 命令提示符中,在 DLL 上运行 Dumpbin.exe /exports 以查看导出。如果同一目录下有 .pdb 文件,请删除该文件。
There are only two failure modes for GetProcAddress:
The exported named of this function is not "Function" unless you used a .def file to rename the export or created a 64-bit DLL. It will be "_Function@16" for a 32-bit build. The @16 postfix would be strongly associated with the fact that you have trouble making it work for functions with any arguments.
From the Visual Studio Command Prompt run Dumpbin.exe /exports on your DLL to see the exports. Delete a .pdb file in the same directory if there is one.
最好使用带有导出函数名称的模块定义(.def 文件)而不是 __declspec(dllexport)。管理它们要容易得多。
此外,此
#define DllExport extern "C" __declspec (dllexport)
导致导出的 dll 函数名称没有任何 C++“装饰”
It's good idea to use module definition (.def file) with names of exported functions instead of __declspec(dllexport). It's much easier to manage them.
Also this
#define DllExport extern "C" __declspec (dllexport)
causes that exported dll function names are without any c++ "decorations"