错误的从C到C的编组#

时间:2014-09-18 04:43:55

标签: c# c marshalling dllimport

我有以下结构(在C上):

typedef struct Piece
{
    ePieceType PieceType;//enum
    ePlayer Player;//enum
    int IsFirstMove;
} sPiece;

(在C#上):

[StructLayout(LayoutKind.Sequential)]
public struct Piece
{
    public PieceTypeEnum PieceType; //same enum order like ePieceType 
    public PlayerEnum Player; //same enum order like ePlayer 
    public int IsFirstMove;
}

我有以下要导出的功能:

__declspec(dllexport) void InitBoard(sPiece board[8][8]);

C#:

[DllImport("chess_api.dll", SetLastError = true)]
static extern void InitBoard([MarshalAs(UnmanagedType.SafeArray)]Piece[][] board);

我收到以下错误:

enter image description here

我想我也没有编组阵列,你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

答案是:

  

只需声明Piece []并传递一个包含64个元素的数组

发表在Hans Passant的评论中(但不知何故没有提出它作为答案)。