Hello,

From a C# console application I'm trying to call a constructor + methd of a C++ class.
The P/invoke is:

[DllImport("MyClass.dll", EntryPoint = "?Set@CMyClass@@QAEXH@Z")]
static extern void Set_dll(int x);

[DllImport("MyClass.dll", EntryPoint = "??0CMyClass@@QAE@XZ")]
static extern void MyClass_dll();

public MyClass()
{
MyClass_dll();
}

public void Set(int x)
{
Set_dll(x);
}

The C++ class is:

#ifdef MYCLASS_EXPORTS
#define MYCLASS_API __declspec(dllexport)
#else
#define MYCLASS_API __declspec(dllimport)
#endif

class MYCLASS_API CMyClass {
private:
int m_a;
public:
CMyClass(void){m_a = 0;};
// TODO: add your methods here.
void Set (int x){m_a = x;};
};

When the C# code reaches the C++ constructor I'm getting an exception on the line: m_a=0.
It seems m_a has no address yet.

If CMyClass does not contain any attributes, calling the method from C# works fine.

What am I doing wrong ?

Thanks,
Zvika