
Marshaling structures with arrays
[StructLayout(LayoutKind.Sequential,
CharSet=CharSet.Ansi, Pack=1)]
public struct UNIT
{
public short Number ;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=5 ) ]
public string UnitID;
public short Type ;
public string CurrencyID;
public int Values ;
public int InitialCount ;
public int Count ;
public int Minimum ;
public int Maximum ;
public int AppLock ;
public int DevLock ;
public short Status ;
Quote:
}
[ StructLayout( LayoutKind.Sequential, Pack=1 ) ]
public struct INFO
{
public short Count;
public IntPtr List; // UNIT lppList
Quote:
}
I have to call a function defined in a dll written in C.
This function
is toInf( INFO * lpInfo ) that receive a pointer to a
INFO struct.
There isn't any problem yet.
But the List field of the INFO struct is a Pointer to an
array of
pointers to UNIT structures. This is the problem, i
don't know how to
set this field.
Im tryng
INFO info;
UNIT[] units = new UNIT[ 5 ];
IntPtr ptrInfoUnits = IntPtr.Zero;
IntPtr ptrInfo = IntPtr.Zero
//...
// Here i fill the units array
//...
ptrInfoUnits = Marshal.AllocHGlobal( Marshal.SizeOf(
typeof( UNIT ) ) );
Marshal.StructureToPtr( units[ 0 ], ptrInfoUnits ,
false );
info.List = ptrInfoUnits;
info.Count = 5;
ptrInfo = Marshal.AllocHGlobal( Marshal.SizeOf( typeof(
INFO) ) );
Marshal.StructureToPtr( info, ptrInfo , false );
toInf( ptrInfo );
This doesn't give me any good results
My problem is how to set the List field of the INFO
struct.
How to set a pointer to an array of pointers to UNIT
structures ??
May be a IntPtr pointing to an array of IntPtr each one
pointing to an UNIT info ???
Thanks !!!