How to add dll call function to another project

I have a console application in C ++, and I want to call the add () function in another dll project in C ++. How to do it?

+3
source share
2 answers

Use LoadLibrary and then GetProcAddress to get the pointer function.

+5
source

DLL files are available either through the appropriate files .LIBincluded in your project along with their header #include "MyUtils.h". This is called static binding, and all this is done at compile time, as much as you need, and you call the DLL functions as if they were defined in your own application.

, DLL . :

// Declare the 'type' of the function, for easier use.
typedef BOOL (* t_MyFunc)(DWORD dwParam1, int nParam2);

// Declare a pointer to the function. Via this pointer we'll make the call.
t_MyFunc MyFunc     = 0;
BOOL bResult    = FALSE;

// Load the DLL.
HMODULE hModule = LoadLibrary("MyDLL.dll");
assert(hModule);
// Obtain the function address.
MyFunc = (t_MyFunc)GetProcAddress(hModule, "MyDLL.dll");
assert(MyFunc);

// Use the function.
bResult = MyFunc(0xFF00, 2);

// No need in MyDll.dll or MyFunc anymore. Free the resources.
FreeLibrary(hModule);

, , DLL - , , . .

0

All Articles