Reputation: 51
Given a method with this signature in a DLL
int32_t __stdcall ndUDSReadDataByIdentifier(
TD1 *diagRef,
uint16_t ID,
uint8_t dataOut[],
int32_t *len,
int8_t *success);
How does the C# external call look like?
I tried:
[DllImport("nidiagcs.dll")]
public static extern Int32 ndUDSReadDataByIdentifier(
ref TD1 diagRef,
[MarshalAs(UnmanagedType.U2)] UInt16 ID,
byte[] dataOut,
[MarshalAs(UnmanagedType.U4)] ref Int32 len,
[MarshalAs(UnmanagedType.U1)] ref byte success);
The call is executed but the dataOut is not filled.
Upvotes: 1
Views: 870
Reputation: 51
Okay I found the solution.
[DllImport("nidiagcs.dll", CallingConvention = CallingConvention.StdCall)]
private static extern Int32 ndUDSReadDataByIdentifier(
ref TD1 diagRef,
UInt16 ID,
Byte[] dataOut,
ref Int32 len,
out byte success);
This is the correct way to call the function. It was a mistake from my side. One needs to supply a buffer array in dataOut and the according size of the buffer in len. I always set len to 0 which makes the library think the dataOut array has a size of zero so nothing is returned.
Thanks for everyones help!
Upvotes: 2