Advertisement
Guest User

Untitled

a guest
Mar 26th, 2020
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1.  
  2. #define PathToLibrary "D:\\NativeLibrary.dll"
  3.  
  4. #include "windows.h"
  5. #define symLoad GetProcAddress
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8.  
  9. int callSumFunc(char* path, char* funcName, int a, int b);
  10.  
  11. int main()
  12. {
  13. if (!access(PathToLibrary, 0))
  14. printf("File Present");
  15. else
  16. printf("File not Found");
  17.  
  18. // Sum two integers
  19. int sum = callSumFunc(PathToLibrary, "add", 2, 8);
  20. printf("The sum is %d \n", sum);
  21. }
  22.  
  23. int callSumFunc(char* path, char* funcName, int firstInt, int secondInt)
  24. {
  25.  
  26. // Call sum function defined in C# shared library
  27. HINSTANCE handle = LoadLibrary(PathToLibrary);
  28. DWORD ErrorCode = GetLastError();
  29.  
  30. typedef int (*myFunc)();
  31.  
  32. myFunc MyImport = (int)symLoad(handle, funcName);
  33.  
  34. int result = MyImport(firstInt, secondInt);
  35.  
  36. // CoreRT libraries do not support unloading
  37. // See https://github.com/dotnet/corert/issues/7887
  38. return result;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement