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 infoint 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.SequentialPack 2)]
    
struct MyRange
    
{
        public 
Int start;
        public 
Int size;
    }

   [
StructLayout(LayoutKind.SequentialPack 2)]
    
struct MyInfo 
    
{
       public 
Int64 a;
        
// A Null terminated array of ranges.
       
public IntPtr ranges;
    }

      [
DllImport("mydll.dll"SetLastError falseCharSet 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 infosize);
    
byte[] byteRanges= new byte[size];
    
Marshal.Copy(info.rangesbyteRanges0size); 
    
//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