[英]How to load dll in C++
I would like to load Dll in my c++ project, but the problem is I do not have the source code of the Dll that I was using. 我想在我的c ++项目中加载Dll,但问题是我没有我正在使用的Dll的源代码。 So I can't modify anything in the dll eg add export def file, or export c method for the dll.
所以我无法修改dll中的任何内容,例如添加导出def文件,或导出dll的c方法。 Any solution for this situation ?
针对这种情况的解决方案?
Have tried load library function, and it was successful load the Dll. 尝试过加载库函数,并且成功加载了Dll。
How to call the function within the dll without def file, or export c method ? 如何在没有def文件的情况下调用dll中的函数,或者导出c方法?
You need to know what the DLL provides to you. 您需要知道DLL为您提供了什么。 You should get a header files with the definitions of structures (if any) and the function prototype(s) including the calling conventions.
您应该获得带有结构定义(如果有)的头文件和包含调用约定的函数原型。
You can get the list of exported functions with dumpbin /exports TheDll.dll
. 您可以使用
dumpbin /exports TheDll.dll
获取导出函数的列表。 You should further check the CPU it is made for with the dumpbin
command. 您应该使用
dumpbin
命令进一步检查它的CPU。 This avoids a 32/64 bit trouble. 这避免了32/64位的麻烦。
You can load any compatible DLL (32/64) with the LoadLibrary
API function. 您可以使用
LoadLibrary
API函数加载任何兼容的DLL(32/64)。 Include the appropriate header to get the prototype. 包含适当的标头以获取原型。
You get a pointer to an exported function with the GetProcAddress
function. 使用
GetProcAddress
函数获得指向导出函数的指针。 If you have the function signature, you can use this pointer to call the function. 如果您有函数签名,则可以使用此指针调用该函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.