[Mono-list] PInvoke and Marshalling
James Lapalme
james.lapalme@videotron.ca
Tue, 10 Feb 2004 21:19:49 -0500
This is a multi-part message in MIME format.
--Boundary_(ID_pfseDC+HOvZRnjMAoAXOhQ)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT
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;}
}
Why does this code work because most of the example I have seen is always using classes to mimic struct with no methods only fields?
How is the object marshalled?
I have readed .Net nad COM by Nathan/ COM and Net by Troelsen/MSND doc... there is no info on this matter. Where can I get more information on this subject?
What are the limites(inheritence,....) of redefining C+ classes in C# and call C++ code with the redefined classes?
James
P.s this code was tried with the microsoft's version of .Net
--Boundary_(ID_pfseDC+HOvZRnjMAoAXOhQ)
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 7BIT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman" size=3>Dear
All,<BR><BR>I created a dll with the following:<BR><BR>extern "C"
_declspec(dllexport) int myFunction(A*){return a->myInt();}<BR><BR>class
A{<BR> public:<BR>
int i;<BR> int myInt(void){rerturn
i;}<BR>}<BR><BR>I creates a C# client with the folllowing:<BR><BR>public class
MyClient{<BR><BR>
[DllImport("MyDll.dll")]<BR> public static extern in
myFunction(A a);<BR><BR> public static void
Main(){<BR><BR> A a = new
A();<BR>
a.i=5;<BR>
Console.WriteLine(myFunction(a));<BR>
}<BR>}<BR><BR>[StructureLayout(LayputKind.Sequential)]<BR>public class
A{<BR> public int
i;<BR> public int myInt(void){rerturn
i;}<BR>}<BR><BR><BR>Why does this code work because most of the example I have
seen is always using classes to mimic struct with no methods only
fields?</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman"
size=3></FONT></FONT> </DIV>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman" size=3>How is the
object marshalled?</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman"
size=3></FONT></FONT> </DIV>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman" size=3>I have readed
.Net nad COM by Nathan/ COM and Net by Troelsen/MSND doc... there is no info on
this matter. Where can I get more information on this
subject?</FONT></FONT></DIV>
<DIV> </DIV>
<DIV>What are the limites(inheritence,....) of redefining C+ classes in C# and
call C++ code with the redefined classes?<FONT face=Arial size=2><FONT
face="Times New Roman" size=3><BR><BR>James</FONT><BR><BR>P.s this code was
tried with the microsoft's version of .Net</DIV></FONT></BODY></HTML>
--Boundary_(ID_pfseDC+HOvZRnjMAoAXOhQ)--