Explicit Linking
The harder way to load a DLL is a little bit more complicated. You will need function pointers and some Windows functions. But, by loading DLLs this way, you do not need the .lib or the header file for the DLL, only the DLL. I'll list some code and then explain it.
Find more about DLL from here
- #include <iostream>
- #include <windows.h>
- typedef int (*AddFunc)(int,int);
- typedef void (*FunctionFunc)();
- int main()
- {
- AddFunc _AddFunc;
- FunctionFunc _FunctionFunc;
- HINSTANCE hInstLibrary = LoadLibrary("DLL_Tutorial.dll");
- if (hInstLibrary)
- {
- _AddFunc = (AddFunc)GetProcAddress(hInstLibrary, "Add");
- _FunctionFunc = (FunctionFunc)GetProcAddress(hInstLibrary,
- "Function");
- if (_AddFunc)
- {
- std::cout << "23 = 43 = " << _AddFunc(23, 43) << std::endl;
- }
- if (_FunctionFunc)
- {
- _FunctionFunc();
- }
- FreeLibrary(hInstLibrary);
- }
- else
- {
- std::cout << "DLL Failed To Load!" << std::endl;
- }
- std::cin.get();
- return 0;
- }
No comments:
Post a Comment