PInvokes with managed and unmanaged objects
Dear All,
I created a dll with the following:
extern "C" _declspec(dllexport) int myFunction(A*){return a->myInt();}
class A{
public:
int i;
int myInt(void){rerturn i;}
}
I creates a C# client with the folllowing:
public class MyClient{
[DllImport("MyDll.dll")]
public static extern in myFunction(A a);
public static void Main(){
A a = new A();
a.i=5;
Console.WriteLine(myFunction(a));
}
}
[StructureLayout(LayputKind.Sequential)]
public class A{
public int i;
public int myInt(void){rerturn i;}
}
This code works.... should I be surpise that I'm able to minic unmanaged
classes with managed classes, marshall the managed classes through PInvoke
and then let unmanaged code call methods on the managed classes...?
Is this code good or should I be avoiding this and only use managed classes
to minic unmanaged structures that contain no methods?
James