Marshaling ushort[,] multidimensional array in C# -


i've inherited code need interface with. there marshaled command want call c#. code call looks this;

[dllimport(dll_path, charset = charset.ansi, callingconvention = callingconvention.stdcall)]     public static extern void readtable([marshalas(unmanagedtype.lparray)] ushort[,] buffer); 

so 'readtable' command fills in multidimensional array 'buffer'.

i'm not able well, here (non-compiling) attempt;

ushort[,] mytable = new ushort[5,100];   // multidimensional array  unsafe {   fixed (ushort* inputptr = &mytable[0, 0])   {       readtable(inputptr);   } } 

obviously not compiling, i'm of newbie fix error.

i want declare;

fixed(ushort[,]* inputptr = &mytable) 

but nonsense.

anyone understand plight? heaps!

try this:

ushort[,] mytable = new ushort[5,100]; readtable(mytable); 

unless readtable keeps pointer after returns, marshaler's pinning , unpinning array work fine you.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -