2 u010035762 u010035762 于 2014.01.04 10:47 提问

VB调用C++编写的DLL,无报错但是自动弹出

小弟编写了一个C++的DLL,其头文件nihe.h如下:
#include "stdafx.h"
#define EXPORT _declspec(dllexport)
extern "C" EXPORT void matching(double dGPSData[],unsigned int GPSCounts32,double dPlaneData[],unsigned int u32PlaneCounts,double R[], unsigned int u32Rcounts,double T[],unsigned int u32Tcounts,double K,bool bK,double GABC[],double Gxyz[]);

源文件nihe.cpp如下:
#include "nihe.h"
#include "stdafx.h"
typedef void (*mat)(double dGPSData[],unsigned int GPSCounts32,double dPlaneData[],
unsigned int u32PlaneCounts,double R[], unsigned int u32Rcounts,double T[],unsigned int u32Tcounts,double K,bool bK/*,double GABC[],double Gxyz[]*/);
typedef void (*_mat)(double GABC[],double Gxyz[]);

void matching(double dGPSData[],unsigned int GPSCounts32,double dPlaneData[],
unsigned int u32PlaneCounts,double R[], unsigned int u32Rcounts,double T[],unsigned int u32Tcounts,double K,bool bK,double GABC[],double Gxyz[])
{
HMODULE hMod =LoadLibrary("RT_Calculation.dll");
if(hMod!=NULL)
{
mat showinfo1;
_mat showinfo2;
showinfo1=(mat)GetProcAddress(hMod,"fnwMPS_MeasrNet_Get_R_T");
showinfo2=(_mat)GetProcAddress(hMod,"BFG54Parameter");
if(showinfo1 && showinfo2 )
{
showinfo1(dGPSData, GPSCounts32, dPlaneData, u32PlaneCounts, R, u32Rcounts, T, u32Tcounts, K, bK);

showinfo2(GABC, Gxyz);
}
}
}

之后,我做了一个VB的调用文件,在VB模块里,调用DLL及其函数:
Public Declare Sub matching Lib ".\nihe.dll" (ByRef dGPSData As Double, ByVal u32GPSCounts As UInteger, ByRef dPlaneData As Double, ByVal u32PlaneCounts As UInteger, ByRef R As Double, ByVal u32Rcounts As UInteger, ByRef T As Double, ByVal u32Tcounts As UInteger, ByRef K As Double, ByVal bK As Boolean, ByRef GABC As Double, ByRef Gxyz As Double)

然后做了一个按钮,期待吗如下:
Dim dGPSData(8), GABC(5), Gxyz(2) As Double
Dim u32GPSCounts As UInteger = 9
Dim dPlaneData(8) As Double
Dim u32PlaneCounts As UInteger = 9
Dim R(8) As Double
Dim u32Rcounts As UInteger = 9
Dim T(2) As Double
Dim u32Tcounts As UInteger = 3
Dim K As Double = 1.0
Dim bK As Boolean = False
dGPSData(0) = 1731.48
dGPSData(1) = 732.16
dGPSData(2) = 1082.66

    dPlaneData(0) = 1590
    dPlaneData(1) = 200
    dPlaneData(2) = 1000

    dGPSData(3) = -281.33
    dGPSData(4) = 3798.74
    dGPSData(5) = 1379.06

    dPlaneData(3) = 468
    dPlaneData(4) = 3690
    dPlaneData(5) = 678

    dGPSData(6) = 4936.98
    dGPSData(7) = 4316.22
    dGPSData(8) = 84.77

    dPlaneData(6) = 5760
    dPlaneData(7) = 2689
    dPlaneData(8) = 270

    matching(dGPSData(0), u32GPSCounts, dPlaneData(0), u32PlaneCounts, R(0), u32Rcounts, T(0), u32Tcounts, K, bK, GABC(0), Gxyz(0))
    'matched(GABC(0), Gxyz(0))

    TextBox1.Text = R(0)
    TextBox2.Text = R(1)
    TextBox3.Text = R(2)
    TextBox4.Text = R(3)
    TextBox5.Text = R(4)
    TextBox6.Text = R(5)
    TextBox7.Text = R(6)
    TextBox8.Text = R(7)
    TextBox9.Text = R(8)
    TextBox10.Text = T(0)
    TextBox11.Text = T(1)
    TextBox12.Text = T(2)

    TextBox13.Text = GABC(0)
    TextBox14.Text = GABC(1)
    TextBox15.Text = GABC(2)
    TextBox16.Text = GABC(3)
    TextBox17.Text = GABC(4)
    TextBox18.Text = GABC(5)

    TextBox19.Text = Gxyz(0)
    TextBox20.Text = Gxyz(1)
    TextBox21.Text = Gxyz(2)

启动调用程序之后,每次一点按钮,就自动弹出但也没报错。大神们能不能帮帮小弟看看到底哪里有问题啊,我总觉得是参数传递出了问题但是又找不到哪里出错了

1个回答

oyljerry
oyljerry   Ds   Rxr 2015.01.04 23:14

制定调用约定为_stdcall

Csdn user default icon
上传中...
上传图片
插入图片