Guest User

Untitled

a guest
Jun 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. // CallDllFunction.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. using namespace std;
  7.  
  8. // Defining the function prototype.
  9. typedef double (__cdecl *AddType)(double a, double b);
  10.  
  11. int main()
  12. {
  13. HINSTANCE dllHandle = NULL;
  14. AddType AddPtr = NULL;
  15. double result = 0.0;
  16.  
  17. // Load the dll.
  18. dllHandle = LoadLibrary(L"MathLibrary.dll");
  19. if (dllHandle == NULL) {
  20. cerr << "Failed to load library with error code " << GetLastError() << endl;
  21. return EXIT_FAILURE;
  22. }
  23.  
  24. // Get a pointer to the add function in MathLibrary.dll.
  25. AddPtr = (AddType) GetProcAddress(dllHandle, "?Add@Functions@MathLibrary@@SANNN@Z");
  26. if (AddPtr == NULL) {
  27. cerr << "Could not find add function. Error code " << GetLastError() << endl;
  28. return EXIT_FAILURE;
  29. }
  30.  
  31. // The moment of truth...
  32. result = AddPtr(1.0, 2.0);
  33. cout << "The result is " << result << endl;
  34.  
  35. return EXIT_SUCCESS;
  36. }
Add Comment
Please, Sign In to add comment