我有以下的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