Hi All,
I have some problems when I include assembler code in C++ function wrapped in a class. C++ code is compiled to 86 bit dll which is a part of a WPF .NET project,
compiled for 86,
I use P/Invoke, not C++/ CLI
I am working on Visual Studio 2017
The app starts on my pc, but it crashes when I run it on different virtual Machines, 64, 32, ... I think couldn't add dll...
I am new in assembler, is my code correct? May be I have to write inside assembler function something more? Here is my code:
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:
#ifndef MYCLASS_H
#define MYCLASS_H
class __declspec(dllexport) MyClass
{
public:
int * resultEAX ;
int Foo1();
void SetFoo_1();
int GetEAX();
};
#endif
**
extern "C" {
#endif
__declspec(dllexport) MyClass* Create();
__declspec(dllexport) void Dispose(MyClass* a_pObject);
__declspec(dllexport) void SetFoo_1(MyClass* a_pObject);
__declspec(dllexport) int GetEAX(MyClass* a_pObject);
#ifdef __cplusplus
}
#endif
**
And I call the class from WPF .NET using managed C# code:
Int32 a = 0;
IntPtr pMyClass = MyClassHandling.Create();
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;