Hi all,
I have the folowing C structs in a dll :
PHP Code:
#pragma pack(push, 2)
struct MyRange {
int start;
int size;
}
struct MyInfo {
LARGE_INTEGER a;
// A Null terminated array of ranges.
MyRange ranges[1];
};
The struc MyInfo is passed to a C Function and is filled with some range info.
The C Function looks like this :
PHP Code:
void FillMyInfo(MyInfo info, int size);
I want to call this from C#.... I am doing the marshalling but I have a problem with the Run member
in C#
PHP Code:
[StructLayout(LayoutKind.Sequential, Pack = 2)]
struct MyRange
{
public Int start;
public Int size;
}
[StructLayout(LayoutKind.Sequential, Pack = 2)]
struct MyInfo
{
public Int64 a;
// A Null terminated array of ranges.
public IntPtr ranges;
}
[DllImport("mydll.dll", SetLastError = false, CharSet = CharSet.Unicode)]
public static extern void FillMyInfo(
ref MyInfo info,
int size);
//Calling the FillMyInfo
int size = 2xMarshal.SizeOf(MyRange);//Supposing the dll is filling two range
MyInfo info = new MyInfo();
info.ranges = Marshal.AllocHGlobal(size);
FillMyInfo(ref info, size);
byte[] byteRanges= new byte[size];
Marshal.Copy(info.ranges, byteRanges, 0, size);
//Here I get a Memory exception, accessing protected Memory
While debuging, the struct is well filled in the C dll, and the begining of the IntPtr seams good...
I tried many alternatives for the type of the ranges member of the MyInfo struc (byte[], MyRange[]), nothing seems to copy the ranges member back to C#, the a member is well returned.
Thank you