Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TESTAPP.CPP (Load dll)
- #include <windows.h>
- #include <stdio.h>
- #define DLL_NAME "TestDll.dll"
- #define DLL_FUNC "AddFunc"
- typedef int (*DllFuncPtr)(int x, int y);
- int main()
- {
- printf("TestApp [Dynamic Dll Loading]\n");
- printf("Loading dll: "DLL_NAME"\n");
- HMODULE dll = LoadLibraryA(DLL_NAME);
- if (dll != NULL) { printf("Dll loaded!\n"); }
- else { printf("Dll failed to load!\n"); return 1; }
- printf("Getting function: "DLL_FUNC"\n");
- DllFuncPtr dllFunction = (DllFuncPtr)GetProcAddress(dll, DLL_FUNC);
- if (dllFunction != NULL) { printf("Function found!\n"); }
- else { printf("Function not found!\n"); return 1; }
- int testx = 10, testy = 15;
- int ret = dllFunction(testx, testy);
- printf("Values given: %d, %d\n", testx, testy);
- printf("Value returned: %d\n", ret);
- FreeLibrary(dll);
- return 0;
- }
- //TESTDLL.cpp (dll)
- __declspec(dllexport) int AddFunc(int x, int y)
- {
- return x + y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement