使用DLL将复合C ++结构(包含向量)转换为VB

时间:2014-03-15 21:47:06

标签: c++ vb.net dll vector struct

我的复合c ++ struct通过DLL转换为VB有问题。

我使用了简单的功能

extern "C" __declspec(dllexport) int Function()
{return 4;}

在C ++中使用此代码在VB上轻松阅读

<DllImport("dlltest.dll", EntryPoint:="Function", CallingConvention:=CallingConvention.Cdecl)>
    Private Shared Function AddFunction() As Integer
    End Function

当我尝试读取我的其他函数时会出现问题,该函数返回一个结构:

extern "C" __declspec(dllexport) info Func()
{
    ...
    info K;
        ...
    return K;
}

我用它将此函数导入VB

<DllImport("dlltest.dll", EntryPoint:="Func", CallingConvention:=CallingConvention.Cdecl)>
    Private Shared Function AdFunction() As info
    End Function

我在C ++中描述了结构信息,如下所示:

struct time
{
    double start;
    double duration;
    double finish;
};
struct busy
{
    time T;
    int operation;
    int product;
    int order;
};
struct operation
{
    string name;
    int lane;
    time T;
    int parallel;
    int coherent;
    int product;
};
struct product
{
    string name;
    int quantity;
    int o;
    vector<operation> O;
    int levels;
    vector <double> LevelTime;
};
struct order
{
    int id;
    int p;
    vector<product> P;
    string date;
};
struct lane
{
    string name;
    int t;
    int b;
    vector<time> T;
    vector<busy> B;
    operation O;
};
struct info
{
    vector <lane> L;
    int l;
    vector <order> O;
    int o;
};

我在VB语言中描述了相同的结构,但程序无法读取我的信息。我也可以显示VB结构。

Public Structure time
    Public start As Double
    Public duration As Double
    Public finish As Double
End Structure
Public Structure busy
    Public T As time
    Public operation As Integer
    Public product As Integer
    Public order As Integer
End Structure
Public Structure operation
    Public name As String
    Public lane As Integer
    Public T As time
    Public parallel As Integer
    Public coherent As Integer
    Public product As Integer
End Structure
Public Structure product
    Public name As String
    Public quantity As Integer
    Public o As Integer
    Dim OO As operation
    Public levels As Integer
    Dim LevelTime As Double
End Structure
Public Structure order 
    Public id As Integer
    Public p As Integer
    Dim PP As product
    Public date As String
End Structure
Public Structure lane 
    Public name As String
    Public t As Integer 
    Public b As Integer
    Dim TT As time
    Dim BB As busy
    Public O As operation
End Structure
Public Structure info
    Dim TT As lane
    Public t As Integer
    Dim OO As order
    Public O As Integer
End Structure

这可能是太多不相关的文字,但我真的想知道如何解决转换问题。如果我的英语技能看起来很糟糕,请提前致谢并抱歉。)。

0 个答案:

没有答案