C# calling C function that returns struct with fixed size char array

后端 未结 3 1603
别那么骄傲
别那么骄傲 2020-12-16 12:24

So, there have been many variants of this question, and after looking at several I still can\'t figure it out.

This is the C code:

typedef struct
{
u         


        
3条回答
  •  半阙折子戏
    2020-12-16 13:02

    The problem is that the native function returns a non-blittable type as a return value.

    http://msdn.microsoft.com/en-us/library/ef4c3t39.aspx

    P/Invoke cannot have non-blittable types as a return value.

    You cannot p/Invoke that method. [EDIT It is actually possible, see JaredPar's answer]

    Returning 132 bytes by value is a bad idea. If this native code is yours, I would fix it. You can fix it by allocating the 132 bytes and returning a pointer. Then add a FreeFrame method to release that memory. Now it can be p/Invoked.

    Alternately, you could change it to accept a pointer to the Frame memory that it will fill in.

提交回复
热议问题