我已经有几年没有做过任何 Windows 编程了,而且我对如何使用 dllimport 有点生疏了。我有一些类似的事情:
extern "C"
{
__declspec(dllimport) int myFunct();
}
int main()
{
cout<<myFunct();
}
我收到 2 个未解决的外部链接器错误和一条警告,提示 /DELAYLOAD:myLib.dll 被忽略,因为未找到从中导入的内容。
我在这里缺少什么?我认为我可以将 DLL 添加到延迟加载路径,并且链接器会计算将其用于 dll 导入?
这是一个第三方 DLL,没有 .h 或 .lib 文件。
如果你想在运行时链接DLL,你根本不需要导入符号。
只需声明一个函数指针类型,然后LoadLibrary() http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175%28v=vs.85%29.aspx/LoadLibraryEx() http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179%28v=vs.85%29.aspx,最后从中检索函数指针GetProcAddress() http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212%28v=vs.85%29.aspx.
示例(为简洁起见,省略了错误处理):
typedef int (*MyFunct_t)();
auto myDLL = LoadLibrary("mydll.dll");
auto MyFunct = (MyFunct_t)GetProcAddress(myDLL, "MyFunct");
MyFunct();
(this code is only to show general procedure, it was never compiled and tested and could contain typos and syntax errors, feel free to edit this post to fix them)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)