如何通过.net传递2D数组调用C ++函数?

时间:2011-06-23 21:30:58

标签: .net vb.net visual-c++ pinvoke

我试图用以下声明调用该方法:

extern "C" __declspec(dllimport) int __stdcall CalcDDtable(struct ddTableDeal tableDeal, struct ddTableResults * tablep);

结构如下定义:

    struct ddTableDeal {
  unsigned int cards[4][4];
};

struct ddTableResults {
  int resTable[5][4];
};

我试着这样称呼它:

  <DllImport("dds.dll", CallingConvention:=CallingConvention.StdCall)>
Public Shared Function CalcDDtable(ByVal deal As TableDeal, ByRef results As TableResults) As Integer
End Function

Public Function CalculateDeal() As Integer
    Dim tableDeal As TableDeal
    Dim tableResults As TableResults
    Dim cards(3, 3) As Integer
    cards(0, 0) = 32764
    cards(1, 1) = 32764
    cards(2, 2) = 32764
    cards(3, 3) = 32764
    tableDeal.Cards = cards

    Dim results(4, 3) As Integer
    tableResults=new TableResults
    tableResults.Results = results

    Dim errorCode = CalcDDtable(tableDeal, tableResults)

    Return errorCode
End Function

End Class

Public Structure TableDeal
    Dim Cards(,) As Integer
End Structure

Public Structure TableResults
    Dim Results(,) As Integer
End Structure

结构应该都是二维数组,索引分别为4,4和5,4。第二个是out参数。

我哪里错了?

对于那些想要了解的人:这是Bo Haglund撰写的double dummy solver .dll

1 个答案:

答案 0 :(得分:1)

可以找到答案here