Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyClass.cpp:
- int MyClass::Foo_1()
- {
- __asm
- {
- mov eax, 0
- }
- }
- void MyClass::SetFoo_1()
- {
- resultEAX = new int;
- int a = -1;
- try
- {
- a = Foo_1();
- }
- catch (int e) { }
- if (a == 0) {
- *resultEAX = 0;
- }
- else {
- *resultEAX = 1;
- }
- }
- MyClass.h:
- #ifndef MYCLASS_H
- #define MYCLASS_H
- class __declspec(dllexport) MyClass {
- public:
- int * resultEAX ;
- int Foo1();
- void SetFoo_1();
- int GetEAX();
- };
- #endif
- **
- MyClassCaller.h:
- extern "C" {
- #endif
- __declspec(dllexport) MyClass* Create();
- __declspec(dllexport) void Dispose(MyClass* a_pObject);
- __declspec(dllexport) void SetFoo_1(MyClass* a_pObject);
- __eclspec(dllexport) int GetEAX(MyClass* a_pObject);
- #ifdef __cplusplus
- }
- #endif
- **
- MyClassCaller.cpp:
- Graphics* Create()
- {
- return new MyClass();
- }
- void Dispose(MyClass * a_pObject)
- {
- if (a_pObject != NULL)
- {
- delete a_pObject;
- a_pObject = NULL;
- }
- }
- void SetFoo_1(MyClass * a_pObject)
- {
- if (a_pObject != nullptr)
- {
- a_pObject->SetFoo_1();
- }
- }
- int GetEAX(MyClass * a_pObject)
- {
- if (a_pObject != NULL)
- {
- return a_pObject->GetEAX();
- }
- return 0;
- }
- And I call the class from WPF .NET using managed C# code:
- IntPtr pMyClass = MyClassHandling.Create();
- Int32 a = 0;
- Int64 b = 0;
- long c = 0;
- long rslt = 0;
- try
- {
- MyClassHandling.SetFoo_1(pMyClass);
- if (Environment.Is64BitOperatingSystem)
- {
- //"SysWOW64"
- b = MyClassHandling.GetEAX(pMyClass);
- ……
- }
- else
- {
- //"system32"
- a = pMyClassHandling.GetEAX(pGraphics);
- …
- }
- MyClassHandling.Dispose (pGraphics);
- pMyClass = IntPtr.Zero;
- **
- [DllImport("SomeAssemblerFunctions.dll")]
- static public extern IntPtr Create();
- [DllImport("SomeAssemblerFunctions.dll")]
- static public extern void Dispose(IntPtr pGraphicsObject);
- [DllImport("SomeAssemblerFunctions.dll"
- , EntryPoint = "SetGraphicMode1")]
- static public extern void SetFoo_1(IntPtr pGraphicsObject);
- [DllImport("SomeAssemblerFunctions.dll"
- , EntryPoint = "GetEAX")]
- static public extern int GetEAX(IntPtr pGraphicsObject);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement