小弟正在学习一个项目,涉及到用VB调用VC写的dll,可是调试了很多次一直都报下面这个错:
Debug error!
Program: C:\Program Files\Microsoft Visual Studio\VB98\vb6.exe
abnormal program termination
然后VB就自动关闭了,我实在没辙了,各位大侠能不能帮我看看啊,下面是VC的dll中我调用的函数以及VB中的声明.VC:
int __stdcall Start(const LPCTSTR CfgPath)
VB声明语句:
Private Declare Function Start Lib "VcleD" (ByVal CfgFile As String) As LongVB调用语句
Dim iRet As LongiRet = Start(App.Path)

解决方案 »

  1.   

    VC:
    int __stdcall Start(const LPCTSTR CfgPath)是不是应该改为
    extern   "C"   __declspec(dllexport)   int __stdcall Start(const LPCTSTR CfgPath)
       
      

  2.   

    VC++部分:extern "C" _declspec(dllexport) int __stdcall MidStr(CHAR * src,CHAR * dest)
    {
        //AFX_MANAGE_STATE(AfxGetStaticModuleState());
        strcpy(dest,src+1);
        return 0;

    VB部分:
    声明:Private Declare Function MidStr Lib "Dll.dll" (ByVal src As String, ByVal dest As String) As Long  调用:Dim i As Long, s As String * 255   
    tempstr = "Hello!World"  
    i = MidStr(tempstr, s)  或者 i = MidStr("Hello!World", s)   
    MsgBox s, vbExclamation   
      

  3.   

    我前一阵子写过VB/VC双向通讯的代码,应该使用unicode传递,并且用SysAllocString这样的系统Api产生的字符串来传递。