C++程序中:USB2080_Read.cpp文件中:extern "C"
void EXPORT _stdcall StartDeviceAD(int FirstChannel,int LastChannel, int Usb_Port, CString filename)    //读取卡件数据,启动线程
{
......
}extern "C"
void EXPORT _stdcall StopDeviceAD()//释放卡件
{
........
}USB2080_Read.def文件中:EXPORTS
    StartDeviceAD; Explicit exports can go here
    StopDeviceAD ; Explicit exports can go hereUSB2080_Read.h文件中:
extern "C"
{
void EXPORT _stdcall StartDeviceAD(int FirstChannel,int LastChannel, int Usb_Port, CString filename);
void EXPORT _stdcall StopDeviceAD();
}
VB程序中:Private Declare Sub StartDeviceAD Lib "C:\WINDOWS\system\USB2080_Read.dll" _
(ByVal FirstChannel As Long, ByVal LastChannel As Long, ByVal Usb_Port As Long, ByVal filename As String)Private Declare Sub StopDeviceAD Lib "C:\WINDOWS\system\USB2080_Read.dll" ()然后在后面用。
但是,当退出VB程序时,每两次就会发生一次错误。提示:Chamber(VB的程序名)遇到一个问题,需要关闭,对此带来的不便深表歉意。

解决方案 »

  1.   

    具体的错误如下(我的系统是英文版的,所以提示为英文):ChamberChamber has encountered a problem and needs to close. We are sorry for the inconvenience.If you were in the middle of something, the information you were working on might be lost.Please tell Microsoft about this problem.We have created an error report that you can send to help us improve chamber. We will treat this report as confidential and anonymous.To see what data this error report contains, click here.我单击后,出现如下界面:Error signatureAppName: chamber-070329.exe     AppVer:1.0.0.0         ModName:ntdll.dll
    ModVer:5.1.2600.2180       offset: 00010f29Reporting Details:This error report includes: information regarding the condition of chamber when the problem occurred; the operating system version and computer hardware in use; your Digital Product ID, which could be used to indentify your license; and the Internet Protocol(IP) address of your computer.We do not intentionally collect your files, name, address, email address or any other form of personally identifiable information. However, the error report could contain customer-specific information such as data from open files. While this information could potentially be used to determine your identity, if present, it will not be used.The data that we collect will only be used to fix the problem. If more information is available, we will tell you when you report the problem. This error report will be sent using a secure connection to a database with limited access and will not be used for eting perposes.To view technical information about the error report, click here.
    To see our data collection policy on the web, click here.
      

  2.   

    不是呀?C++中的int型对应vb中的long型
      

  3.   

    那这个不是 VB 调用 DLL的问题了,你DLL都能调用了,只是在退出的时候crash,看看DLL里面的代码吧
      

  4.   

    VB程序中的最后一个byVal要改为byRef
    Private Declare Sub StartDeviceAD Lib "C:\WINDOWS\system\USB2080_Read.dll" _
    (ByVal FirstChannel As Long, ByVal LastChannel As Long, ByVal Usb_Port As Long, byRef filename As String)
      

  5.   

    vb 调 vc 的 dll 都是 __stdcall 的,即被调者自己退栈,如果是约定有错,在一开始就会报调用约定错误
      

  6.   

    我怀疑可能还是CString参数出的问题。把它该成char*试下
      

  7.   

    CString 很难说,但是 string 肯定可以, char * 也没问题,倒是在 vb 里面,我没传过 string ,一般我调 dll 的时候传 byte()
      

  8.   

    现在又有一个问题比那个更棘手的问题。我在VB调用C++的Dll是,一共有四个参数,其中一个是文件名字。如果文件名字太长,会不会出错?
      

  9.   

    谢谢大家!问题已解决。我将最后一个参数删掉了,就可以了。可能是CString类型问题。
      

  10.   

    谢谢大家!问题已解决。我将最后一个参数删掉了,就可以了。可能是CString类型问题。