Advertisement
Guest User

WPF.NET app 86 with C++ dll 86

a guest
May 13th, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. MyClass.cpp:
  2. int MyClass::Foo_1()  
  3. {  
  4.     __asm  
  5.   {  
  6.     mov eax, 0  
  7.   }
  8. }  
  9. void MyClass::SetFoo_1()  
  10. {  
  11.   resultEAX = new int;  
  12.   int a = -1;  
  13.   try  
  14.   {  
  15.     a = Foo_1();  
  16.   }  
  17.   catch (int e) { }  
  18.   if (a == 0) {  
  19.   *resultEAX = 0;  
  20.   }  
  21.   else {  
  22.     *resultEAX = 1;  
  23.   }  
  24. }  
  25.  
  26. MyClass.h:  
  27. #ifndef MYCLASS_H  
  28. #define MYCLASS_H  
  29. class __declspec(dllexport) MyClass {  
  30. public:  
  31. int * resultEAX ;  
  32. int Foo1();  
  33. void SetFoo_1();  
  34. int  GetEAX();  
  35. };  
  36. #endif  
  37.  
  38. **  
  39. MyClassCaller.h:  
  40. extern "C" {  
  41. #endif  
  42. __declspec(dllexport) MyClass* Create();  
  43. __declspec(dllexport) void Dispose(MyClass* a_pObject);  
  44. __declspec(dllexport) void SetFoo_1(MyClass* a_pObject);  
  45. __eclspec(dllexport) int GetEAX(MyClass* a_pObject);  
  46. #ifdef __cplusplus
  47. }  
  48. #endif  
  49.  
  50. **  
  51. MyClassCaller.cpp:  
  52. Graphics* Create()  
  53. {  
  54.   return new MyClass();  
  55. }  
  56.  
  57. void Dispose(MyClass * a_pObject)  
  58. {  
  59.   if (a_pObject != NULL)  
  60.   {  
  61.     delete a_pObject;  
  62.     a_pObject = NULL;  
  63.   }  
  64. }  
  65.  
  66. void SetFoo_1(MyClass * a_pObject)  
  67. {  
  68.   if (a_pObject != nullptr)  
  69.   {  
  70.     a_pObject->SetFoo_1();  
  71.   }  
  72. }  
  73.  
  74. int GetEAX(MyClass * a_pObject)  
  75. {  
  76.   if (a_pObject != NULL)  
  77.   {  
  78.      return a_pObject->GetEAX();  
  79. }  
  80. return 0;  
  81. }  
  82.  
  83. And I call the class from WPF .NET using managed C# code:  
  84. IntPtr pMyClass = MyClassHandling.Create();  
  85. Int32 a = 0;  
  86. Int64 b = 0;  
  87. long c = 0;  
  88. long rslt = 0;  
  89.  
  90. try  
  91. {  
  92.   MyClassHandling.SetFoo_1(pMyClass);  
  93.   if (Environment.Is64BitOperatingSystem)  
  94.   {  
  95.     //"SysWOW64"  
  96.     b = MyClassHandling.GetEAX(pMyClass);  
  97. ……  
  98.   }  
  99.   else  
  100.   {  
  101.     //"system32"  
  102.     a = pMyClassHandling.GetEAX(pGraphics);  
  103.     …  
  104.   }  
  105.  
  106. MyClassHandling.Dispose (pGraphics);
  107. pMyClass = IntPtr.Zero;  
  108. **  
  109.  
  110. [DllImport("SomeAssemblerFunctions.dll")]  
  111. static public extern IntPtr Create();  
  112. [DllImport("SomeAssemblerFunctions.dll")]  
  113. static public extern void Dispose(IntPtr pGraphicsObject);  
  114. [DllImport("SomeAssemblerFunctions.dll"  
  115. , EntryPoint = "SetGraphicMode1")]  
  116. static public extern void SetFoo_1(IntPtr pGraphicsObject);  
  117. [DllImport("SomeAssemblerFunctions.dll"  
  118. , EntryPoint = "GetEAX")]  
  119. static public extern int GetEAX(IntPtr pGraphicsObject);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement