1

Hi I have been working to create a wrapper for dll of a third party C library to be used in C#.

Suppose I have C function from the library:

void functionA(byte data[16], byte buffer[8]);

Is it correct for the following code to be used to wrap the code above ?:

[DllImport("C.dll",CallingConvention=CallingConvention.Cdecl)]
static extern void functionA(byte[] data, byte[] buffer)
1

1 Answer 1

-1

No, that declaration would only be valid for byte *data, which is a pointer to an array.

What you have is a fixed size array, for which you need the following

[DllImport("C.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void functionA(
  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16]
  byte[] data,
  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8]
  byte[] buffer)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.