hi,
i am using unmanaged code.while converting to managed code i use the function
[code=cpp]
public static object ByteArrayToStru cture(byte[] bytearray)
{
IntPtr ptr = IntPtr.Zero;
try
{
ptr = Marshal.AllocHG lobal(bytearray .Length);
Marshal.Copy(by tearray, 0, ptr, bytearray.Lengt h);
return (packet)Marshal .PtrToStructure (ptr, typeof(packet)) ;
}
finally
{
if (ptr != IntPtr.Zero)
{
Marshal.FreeHGl obal(ptr);
}
}
}
[/code]
i an getting the error or accessing a read or write protected area. the memory might be corrupt. how can i debug this error??
kindly help.
thanks in advance
i am using unmanaged code.while converting to managed code i use the function
[code=cpp]
public static object ByteArrayToStru cture(byte[] bytearray)
{
IntPtr ptr = IntPtr.Zero;
try
{
ptr = Marshal.AllocHG lobal(bytearray .Length);
Marshal.Copy(by tearray, 0, ptr, bytearray.Lengt h);
return (packet)Marshal .PtrToStructure (ptr, typeof(packet)) ;
}
finally
{
if (ptr != IntPtr.Zero)
{
Marshal.FreeHGl obal(ptr);
}
}
}
[/code]
i an getting the error or accessing a read or write protected area. the memory might be corrupt. how can i debug this error??
kindly help.
thanks in advance
Comment