Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
请帮助我将此结构数组封送到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 }_C++_Marshalling_Com Interop - Fatal编程技术网

请帮助我将此结构数组封送到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 }

请帮助我将此结构数组封送到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 },c++,marshalling,com-interop,C++,Marshalling,Com Interop,因此,我们传递了数组的第一个元素,而不是数组本身!(联合国?)幸运的是,Net并没有落入这个圈套……用ByVal替换ByRef。数组已被封送为指针 使用ByRef只能匹配C端的bd\u t**。好吧,答案和注释似乎表明没有什么问题,所以…… 我发现了三件事: 1.即使在重建整个解决方案并将新的FlexCalc2.dll复制粘贴到testproject之后,仍然没有替换位于Bin文件夹中的dll的旧副本。 2.我是C++的新手,但是当方法只接收到指针时,你不能使用LLIMED到UBULL迭代数组。

因此,我们传递了数组的第一个元素,而不是数组本身!(联合国?)幸运的是,Net并没有落入这个圈套……

用ByVal替换ByRef。数组已被封送为指针


使用ByRef只能匹配C端的
bd\u t**

好吧,答案和注释似乎表明没有什么问题,所以……
我发现了三件事:

1.即使在重建整个解决方案并将新的FlexCalc2.dll复制粘贴到testproject之后,仍然没有替换位于Bin文件夹中的dll的旧副本。

2.我是C++的新手,但是当方法只接收到指针时,你不能使用LLIMED到UBULL迭代数组。所示的方法使用一种巧妙的方式为每个实现一种
,但在这里它不起作用,因为
bd\u p->boardnumber
返回一个非常高的数字(内存地址?),但
bd\u p[index]。boardnumber
返回1-8范围内的正确数字。我只是将数组的长度作为一个额外的参数发送给函数,我就完成了设置。(我管它叫穷人的选择;-)


3.Hans Passant指出,当C++中的方法签名是<代码> TresturnValm方法(Stutt*TraceEx)< /C> >从Net中,你必须通过数组<代码> ByVal < /> >(在VB6中,这会产生语法错误,并且是不可能的)。传递数组指针的事实并不明显,因为结构的
typedef
中已经声明了
*

不清楚您在问什么。“调试文件”是什么?@luke查看
debprint
语句:它写入调试文件。现在,值为1的BoardSetInfo.BoardSetNumber的值被提取为board->board_number=451266504。那么C++代码读取错误的内存地址?请参阅上面我的其他信息。您需要VB6 hack,因为它还通过引用传递数组。不再需要,因为您现在可以通过VAL传递它。从片段中无法看出还有什么其他错误。Debug+Windows+Memory+Memory1是一个核心调试窗口,用于查看指针指向的对象。对不起,您能详细说明一下吗?如何调试这个?
<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) 
Declare Function FlexCalcBoards Lib "FlexCalc2.dll" (firstBoard As BoardsetInfo)
ret=FlexCalcBoards(Boards(0))