2016-04-02 15 views
0

私は、VB6で書かれた長年前に書かれたレガシープロジェクトを持っています。私はVBで6の十分な情報を見つけることができませんVB 6は古すぎます。私はVB6からdllを呼び出すと間違っていた

VC++から書かれたVB 6からDLLを呼び出そうとしています。問題は、VBがdllを呼び出すときに、VBがクラッシュしたことです。 DLLのエラーだと思ってDLLをデバッグしました。しかし、私はdllがうまく動作することがわかりました。最終的には0を返しますが、VBはdouble配列を成功させませんが、DLLは正常に動作し、dllが終了してVBに戻り、VBがクラッシュします。私は何が起こったのか理解できません。何か案が?ここで

は私のVBコードは

Declare Function parseexcel Lib "parseexcelct.dll" (ByVal thepath As String, ByRef total() As Double, ByRef xy() As Double, ByRef ylxx() As Double, ByRef zy() As Double, ByRef zcy() As Double, ByRef gj1 As Double, ByRef gj2 As Double, ByRef xs1 As Double, ByRef xs2 As Double, ByVal gjt1 As Double, ByVal gjt2 As Double, ByVal xst1 As Double, ByVal xst2 As Double) As Long 


Dim mypathstr As String 

Dim total(0 To 20) As Double 

Dim xy(0 To 20) As Double 
Dim ylxx(0 To 20) As Double 
Dim zy(0 To 20) As Double 
Dim zcy(0 To 20) As Double 

Dim gj1 As Double, gj2 As Double, xs1 As Double, xs2 As Double, gjt1 As Double 
Dim gjt2 As Double, xst1 As Double, xst2 As Double 
Dim result As Integer 

mypathstr = CommonDialog.FileName 
Dim i As Integer 

    'try to initial the array 
    For i = 0 To 20 
    total(i) = 1.1 
    xy(i) = 1.1 
    ylxx(i) = 1.1 
    zy(i) = 1.1 
    zcy(i) = 1.1 
    Next i 

    result = 0 
    gj1 = 1.1 
    gj2 = 1.1 
    xs1 = 1.1 
    xs2 = 1.1 
    gjt1 = 1.1 
    gjt2 = 1.1 
    xst1 = 1.1 
    xst2 = 1.1 

    result = parseexcel(mypathstr, total(), xy(), ylxx(), zy(), zcy(), gj1, gj2, xs1, xs2, gjt1, gjt2, xst1, xst2)'program have crashed here 

あるDLL関数は、私が間違ってやっていること

int __stdcall parseexcel(const char * thepath,double * total,double * xy,double * ylxx,double * zy,double * zcy,double & gj1,double & gj2,double & xs1,double & xs2,double gjt1,double gjt2,double xst1,double xst2 ) 

のですか?

答えて

1

C++ではかなりダムの配列が使用されていますが、いずれの場合でもデフォルトではSAFEARRAYは使用されません。つまり、SAFEARRAYへのポインタを渡すだけではなく、データのBLOBへのポインタが必要です。 VB6で

これは、多くの場合、BYREF最初の配列要素を渡すことによって、アレイのデータの先頭にポインタを渡すことによって、単純に実現されます。この種のものはかなりよくVB6のドキュメントで覆われている

Declare Function parseexcel Lib "parseexcelct.dll" (_ 
    ByVal thepath As String, _ 
    ByRef total As Double, _ 
    ByRef xy As Double, _ 
    ByRef ylxx As Double, _ 
    ByRef zy As Double, _ 
    ByRef zcy As Double, _ 
    ByRef gj1 As Double, _ 
    ByRef gj2 As Double, _ 
    ByRef xs1 As Double, _ 
    ByRef xs2 As Double, _ 
    ByVal gjt1 As Double, _ 
    ByVal gjt2 As Double, _ 
    ByVal xst1 As Double, _ 
    ByVal xst2 As Double) As Long 

result = parseexcel(mypathstr, _ 
        total(0), _ 
        xy(0), _ 
        ylxx(0), _ 
        zy(0), _ 
        zcy(0), _ 
        gj1, _ 
        gj2, _ 
        xs1, _ 
        xs2, _ 
        gjt1, _ 
        gjt2, _ 
        xst1, _ 
        xst2) 

+0

[ここにある](https://msdn.microsoft.com/en-us/library/aa338032(v = VS.60).aspx)は、MSDNのVB6リファレンスライブラリへの(隠れた)リンクです。ご覧のとおり、MicrosoftはVB6のドキュメントを見つけるのを難しくしています。 – BobRodes

関連する問題