G
Guest
I created a wrapper class for a dll written in C. Will the following code
prevent the "ENTIRE ARRAY" from being moved, not just the first array
element? The Wrapper class will be instantiated in a VB .NET application
which doesn't have the ability to prevent the array from being moved.
Thanks in advance,
coz
public class Wrapper
{
[DllImport("CDll.dll", EntryPoint="CDllRead", SetLastError=true,
CharSet=CharSet.Ansi, ExactSpelling=true,
CallingConvention=CallingConvention.Cdecl)]
private static extern uint CDllRead(uint Offset, uint[] Array, uint
Length);
public uint Read(uint Offset, uint[] Array, uint Length)
{
uint typeSize = (uint)Marshal.SizeOf(typeof(uint));
uint len = Length * typeSize;
unsafe
{
fixed(uint* pArray = Array) // Prevent the GC from moving
the array
{
return CDllRead(m_hRfm, Offset, Array, len);
} // end fixed
}// end unsafe
}// end Read()
}// end Wrapper class
prevent the "ENTIRE ARRAY" from being moved, not just the first array
element? The Wrapper class will be instantiated in a VB .NET application
which doesn't have the ability to prevent the array from being moved.
Thanks in advance,
coz
public class Wrapper
{
[DllImport("CDll.dll", EntryPoint="CDllRead", SetLastError=true,
CharSet=CharSet.Ansi, ExactSpelling=true,
CallingConvention=CallingConvention.Cdecl)]
private static extern uint CDllRead(uint Offset, uint[] Array, uint
Length);
public uint Read(uint Offset, uint[] Array, uint Length)
{
uint typeSize = (uint)Marshal.SizeOf(typeof(uint));
uint len = Length * typeSize;
unsafe
{
fixed(uint* pArray = Array) // Prevent the GC from moving
the array
{
return CDllRead(m_hRfm, Offset, Array, len);
} // end fixed
}// end unsafe
}// end Read()
}// end Wrapper class