我有以下的PInvoke :(C
到C#
)的PInvoke不改变对象
[DllImport("chess_api.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void InitBoard([MarshalAs(UnmanagedType.LPArray, SizeConst = 64)]sPiece[] board);
在C
:
__declspec(dllexport) void InitBoard(sPiece board[8][8]);
在InitBoard功能,基质变化的值,但在打电话给PInvoke后我不要看到变化。
sPiece[] board = new sPiece[64];
InitBoard(board);
//Here the values of the board is still initialized (as before the function call) at default values
我试图将变量更改为ref
(虽然它已经引用),但它卡住程序的函数被调用时,所以我不认为这是解决方案。
我花了一段时间才到这里(我对这个主题感兴趣)我很乐意帮助!
编辑:
sPiece在C:
typedef struct Piece
{
ePieceType PieceType; //enum
ePlayer Player; //enum
int IsFirstMove;
} sPiece;
sPiece在C#:
[StructLayout(LayoutKind.Sequential)]
public struct sPiece
{
public ePieceType PieceType;
public ePlayer Player;
public int IsFirstMove;
}
'sPiece'是什么? (在C&C#中) – SLaks 2014-09-21 04:38:51
@SLaks。我在这个问题上加了这个。 OMG !! – 2014-09-21 04:42:11