문제

I have this code in C++

BYTE * apData[3]

How to convert it to C# ? ( I'm using DllImport )

도움이 되었습니까?

해결책

Just use byte[]:

[DllImport EntryPoint="myfunc"]
public extern static void MyFunc(byte[]);

byte[] apData = new byte[3];
MyFunc(apData);

다른 팁

That is an array of length 3, of pointer to BYTE.

Under the assumption that this appears in a struct it is declared like this:

[MarshalAs(UnmanagedType.ByValArray, SizeConst=3)]
IntPtr[] apData;

Alternatively, if the array is passed as a parameter, declare that parameter like this:

[MarshalAs(UnmanagedType.LPArray, SizeConst=3)]
IntPtr[] apData

You can use a raw pointer

[System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint="fun")]
public static extern void fun(System.IntPtr byte_array) ;

just use DLLImport as shown below

[DllImport EntryPoint="func"]
public extern static void Func(byte[]);
byte[] apData = new byte[3];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top