From: "Kevin Hutchison" <
[email protected]>
Subject: Re: Marshalling Structures
Date: Wed, 3 Mar 2004 11:42:58 -0500
Thanks, Peter. I have seen those articles and do refer to them.
Unfortunately, my understanding from them is that marshalling structures can
be done without a problem. In fact,
"As mentioned previously, you can pass structures to unmanaged functions
without worrying, as long as the structure contains blittable types. ... ..
Since the structure contains only blittable types (unmanaged DWORD values
that translate to unsigned 32 bit integers, System.UInt32, in the .NET
Compact Framework), the function can be called easily, as shown in the
following snippet."
But, all the examples that I see infact pass structures *by reference*. I
need to pass them by value. My call works by passing the members of the
structure independently.
[DllImport("api.dll")]
public static extern setsimple ( int SIMPLE_i, int SIMPLE_j );
....
void foo()
{
SIMPLE mySimple = new SIMPLE();
setsimple( mySimple.i, mySimple.j );
}
The API that I am using I have wrapped and working for .NET on the desktop
(yeah!). Enabling the same API for .NET CF looks to require **completely**
rewriting each P/Invoke call. I had expected to have to marshall certain
structures manually, but having to marshall each member of a structure
passed by value independently? ouch.
- K.
Peter Foot said:
There are a pair of good articles here:-
Intro to Marshalling
http://msdn.microsoft.com/mobility/understanding/articles/default.aspx?pull
=/library/en-us/dnnetcomp/html/netcfintrointerp.asp
http://msdn.microsoft.com/mobility/understanding/articles/default.aspx?pull
=/library/en-us/dnnetcomp/html/netcfadvinterop.asp
Peter
--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com |
www.opennetcf.org
Every example I have seen marshals structures containing "blittable" types
by reference. Is it possible to marshal it by value? I am getting the
System.NotSupportedException and every type supported by the marshaller
appears to be sized to 4 bytes (long can only be passed by ref).
Second question - where is GOOD documentation on the .NET CF marshaller?
struct SIMPLE
{
int i;
int j;
}
[DllImport("api.dll")]
public static extern setsimple ( SIMPLE simple );
....
void foo()
{
SIMPLE mySimple = new SIMPLE();
setsimple( mySimple );
}
....