I've inherited some code that I need to interface with. Specifically there is a Marshaled command that I want to call from C#. The code call looks like this;
[DllImport(DLL_PATH, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern void readTable([MarshalAs(UnmanagedType.LPArray)] ushort[,] buffer);
So the 'readTable' command fills in the multidimensional array 'buffer'.
I'm not able to do this very well, but here is my (non-compiling) attempt;
ushort[,] myTable = new ushort[5,100]; // multidimensional array
unsafe
{
fixed (ushort* inputPtr = &myTable[0, 0])
{
readTable(inputPtr);
}
}
Obviously not compiling, but I'm too much of a newbie to fix the error.
I really want to declare;
fixed(ushort[,]* inputPtr = &myTable)
But that is just nonsense.
Anyone understand my plight? Thanks heaps!
Try this:
ushort[,] myTable = new ushort[5,100];
readTable(myTable);
Unless readTable
keeps the pointer after it returns, the marshaler's pinning and unpinning the array will work fine for you.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다