Load C++ dll in CSharp with correct datatypes

Need to load this C++ method from a DLL in CSharp and I'm wondering which datatypes I have to use?

WORD FunA (BYTE Num, BYTE *pFrameTX, DWORD nbbitTX, BYTE
*pFrameRX, DWORD *pnbbitRX)

My first approach was:

[DllImport("Example.Dll")]
public static extern UInt16 FunA(byte Num, Byte[] pFrameTX, UInt32 nbbitTX, ref Byte[] pFrameRX, ref UInt32 pnbbitRX);

Byte[] toSend = new Byte[1], toReceive = new Byte[1024];
toSend[0] = 0x26;
UInt32 numberOfBitsReceived = 0;

FunA(Convert.ToByte(1), toSend, 0, ref toReceive, ref numberOfBitsReceived);

What's wrong here? Can someone help me to find the correct datatypes and calling usage?!

Thanks!

1 answer

  • answered 2018-01-17 08:17 Кирилл Степанов

    Guess you missed the ref modifier in front of pFrameTX.

    [DllImport("Example.Dll")]
    public static extern UInt16 FunA(byte Num, ref Byte[] pFrameTX, UInt32 
    nbbitTX, ref Byte[] pFrameRX, ref UInt32 pnbbitRX);