的C++代碼:請幫我整理一下這個數組結構,以C++
typedef struct {
int bd_number; // number of boardset
int bd_copies; // how many copies
int bd_reserve; // only allocate if needed
} bd_t,*bd_p;
typedef struct boardset_info {
int bs_copies;
int bs_demand;
int bs_allocated;
int bs_ontable_avail;
int bs_ontable_needed;
pstatus bs_status;
int bs_played_sofar;
} bsi_t, *bsi_p;
FC_ERRORCODE dropin_boards(bd_p boards) {
int bs;
bs_info = (bsi_p) calloc(total_boardsets+1, sizeof(bsi_t));//total_boardsets=8
for (bs = 1; bs <= total_boardsets; bs++)
bs_info[bs].bs_status = PS_OUTPLAY;
while (boards->bd_number) { //boards-<bd_number is betweeen 1 and 8
if (boards->bd_number < 0 || boards->bd_number > total_boardsets)
{
debprint("***Error dropin_boards***\n");
debprint("boardsetnumber=%d\n",boards->bd_number);
return FC_ERR_PARAM;
}
//code does not reach this point
}
調用代碼:
<StructLayout(LayoutKind.Sequential)>
Public Structure Flex_BoardSetInfo
Public SetNumber As Integer
Public Copies As Integer
Public IsReserve As Integer
End Structure
<DllImport("FlexCalc2.dll", CallingConvention:=CallingConvention.StdCall)>
Public Shared Function FlexCalcBoards(ByRef boards() As Flex_BoardSetInfo) As Flex_ErrorCode
End Function
Dim boardsets() = GetBoardSetInfo() // creates an arry of 8 BoardsetInfo Elements
_result = FlexCalcWrapper.FlexCalcBoards(boardsets)
上的調試文件的最後一行會記錄bd_p-> board_number = 517237496! Boardnumbers被初始化爲1到8,並且我可以在代碼傳遞給C++ dll之前檢查它是否已經正確完成。 我該如何解決這個問題?
編輯: 從VB6我們用一個黑客獲得這個C++方法工作:
Declare Function FlexCalcBoards Lib "FlexCalc2.dll" (firstBoard As BoardsetInfo)
ret=FlexCalcBoards(Boards(0))
所以,我們通過數組的第一個元素的數組本身代替! (聯合國?)幸運的是,網絡不會因此而陷入...
目前還不清楚你在問什麼。什麼是「調試文件」? – luke 2012-04-27 13:38:55
@luke查看'debprint'語句:它寫入調試文件 – Dabblernl 2012-04-27 13:59:21