user1219310
user1219310

Reputation: 732

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. So I can't modify anything in the dll e.g. add export def file, or export c method for the dll. Any solution for this situation ?

Have tried load library function, and it was successful load the Dll.

How to call the function within the dll without def file, or export c method ?

Upvotes: 1

Views: 1412

Answers (1)

harper
harper

Reputation: 13690

You need to know what the DLL provides to you. 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. You should further check the CPU it is made for with the dumpbin command. This avoids a 32/64 bit trouble.

You can load any compatible DLL (32/64) with the LoadLibrary API function. Include the appropriate header to get the prototype.

You get a pointer to an exported function with the GetProcAddress function. If you have the function signature, you can use this pointer to call the function.

Upvotes: 3

Related Questions