Advertisement
captmicro

Untitled

Apr 23rd, 2010
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. //TESTAPP.CPP (Load dll)
  2. #include <windows.h>
  3. #include <stdio.h>
  4.  
  5. #define DLL_NAME "TestDll.dll"
  6. #define DLL_FUNC "AddFunc"
  7. typedef int (*DllFuncPtr)(int x, int y);
  8.  
  9. int main()
  10. {
  11.     printf("TestApp [Dynamic Dll Loading]\n");
  12.     printf("Loading dll: "DLL_NAME"\n");
  13.     HMODULE dll = LoadLibraryA(DLL_NAME);
  14.     if (dll != NULL) { printf("Dll loaded!\n"); }
  15.     else { printf("Dll failed to load!\n"); return 1; }
  16.     printf("Getting function: "DLL_FUNC"\n");
  17.     DllFuncPtr dllFunction = (DllFuncPtr)GetProcAddress(dll, DLL_FUNC);
  18.     if (dllFunction != NULL) { printf("Function found!\n"); }
  19.     else { printf("Function not found!\n"); return 1; }
  20.     int testx = 10, testy = 15;
  21.     int ret = dllFunction(testx, testy);
  22.     printf("Values given: %d, %d\n", testx, testy);
  23.     printf("Value returned: %d\n", ret);
  24.     FreeLibrary(dll);
  25.     return 0;
  26. }
  27.  
  28. //TESTDLL.cpp (dll)
  29. __declspec(dllexport) int AddFunc(int x, int y)
  30. {
  31.     return x + y;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement