Guest User

Untitled

a guest
Nov 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public static class ExportClass
  2. {
  3. [DllExport(ExportName = "SimpleFunction", CallingConvention = CallingConvention.StdCall)]
  4. public static int SimpleFunction(int a, int b)
  5. {
  6. return a + b;
  7. }
  8.  
  9. [DllExport(ExportName = "CPPObjectMethodCall", CallingConvention = CallingConvention.StdCall)]
  10. public static bool CPPObjectMethodCall(IntPtr cppObject)
  11. {
  12. // How to make call of c++ object method here?
  13. }
  14.  
  15. }
  16.  
  17. class CPPClass
  18. {
  19. public :
  20. CPPClass() {}
  21.  
  22. ~CPPClass() {}
  23.  
  24. void CPPClassMethodCall(std :: string text)
  25. {
  26. MessageBoxA(NULL, text.c_str(), "Message", 0);
  27. }
  28. };
  29.  
  30.  
  31. void TestFunction()
  32. {
  33. HMODULE hDLL = LoadLibraryA("LibCS.dll");
  34.  
  35. typedef int (*SIMPLEFUNCTION)(int a, int b);
  36. typedef bool (*CPPOBJECTMETHODCALL)(void * cppObject);
  37.  
  38. SIMPLEFUNCTION SimpleFunction = (SIMPLEFUNCTION)GetProcAddress(hDLL, "SimpleFunction");
  39. CPPOBJECTMETHODCALL CPPObjectMethodCall = (CPPOBJECTMETHODCALL)GetProcAddress(hDLL, "CPPObjectMethodCall");
  40.  
  41. int x = SimpleFunction(1, 2);
  42.  
  43. CPPClass * cppObject = new CPPClass();
  44.  
  45. // Pass pointer to C++ object
  46. CPPObjectMethodCall(cppObject);
  47.  
  48. delete cppObject;
  49.  
  50. FreeLibrary(hDLL);
  51. }
Add Comment
Please, Sign In to add comment