我在 .dll 中有以下代码:
namespace MyNamespace
{
extern "C" __declspec(dllexport) int __stdcall GetOptionID(unsigned long num)
{
return 0;
}
}
这是在 Visual C++ 2010 上编译的,所以我还有一个 .def 文件,其中包含GetOptionID
. 我可以看到该函数已导出,并_GetOptionID@4
使用 dumpbin /exports 损坏为 :
File Type: DLL
Section contains the following exports for MyLibrary.dll
00000000 characteristics
53D269CB time date stamp Fri Jul 25 15:29:31 2014
0.00 version
1 ordinal base
13 number of functions
13 number of names
ordinal hint RVA name
1 0 0006F030 CmdOne = _CmdOne@16
2 1 0006F510 CmdUnimpl = _CmdUnimpl@16
3 2 0006EBB0 DefineThing = _DefineThing@32
4 3 0006E0C0 GetOptionID = _GetOptionID@4
在一个单独的可执行文件中,我尝试检查是否存在GetOptionID
:
HINSTANCE hinst = LoadLibraryEx(file_name, NULL, DONT_RESOLVE_DLL_REFERENCES);
if(!hinst)
return FALSE;
FARPROC_IDI lp = (FARPROC_IDI) GetProcAddress(hinst, "_GetOptionID@4");
auto e = GetLastError();
在调试器中运行这段代码,我可以看到:
LoadLibraryEx
成功 - 我有一个有效的外观hinst
GetProcAddress
失败 -lp
是0x00000000
GetLastError
返回 127
我可以看到该函数已被导出,并且我可以看到它的名称与我正在寻找的入口点相匹配。怎么会GetProcAddress
失败?