小弟目前在学习一个项目,要涉及的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 Long
  
  VB调用语句
  Dim iRet As Long
    
  iRet = Start(App.Path)

解决方案 »

  1.   

    VB调用语句
    Dim iRet As Long
    Dim sPath As String*256
    sPath=App.Path+chr$(0)
    iRet = Start(sPath)
    再试试看。
      

  2.   

    再试这个行不,再不行,我也没辙了…… ^_^
    ' 函数声明:
    'Private Declare Function Start Lib "VcleD" (ByVal CfgFile As String) As Long
    Private Declare Function Start Lib "VcleD" (ByVal pCfgFile As Long) As Long
    ' 调用方法:
    Dim sBuffer() As Byte
    sBuffer = StrConv(App.Path, vbFromUnicode)
    ReDim Preserve sBuffer(UBound(sBuffer) + 1)
    Call Start(VarPtr(sBuffer(LBound(sBuffer))))
      

  3.   

    崩溃啊,还是不行。到底用VB调用VC的dll步骤是怎么样,有没有啥要注意的地方?
    我觉得我上面写的语句貌似没有啥问题啊,为啥一调用就报那个错?
      

  4.   

    对了,不知道的 VC 中是否用宽字符来处理字符串。
    如果是这样,试试这个代码:
    'Private Declare Function Start Lib "VcleD" (ByVal CfgFile As String) As Long
    Private Declare Function Start Lib "VcleD" (ByVal pCfgFile As Long) As LongDim strTemp$
    Dim iRet As Long
    strTemp = App.Path
    iRet = Start(StrPtr(strTemp))
      

  5.   

    刚才查了一下 MSDN :
    LPCSTR Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.可见我的 9F 肯定不适用,而 7F 的代码应该不会有问题。你确认你的 dll 没有问题吗?
      

  6.   

    dll编译的时候没有报错,但是不确定是不是真的没问题.我再试试上面的代码哈
      

  7.   

    哎,还是一样的错,可能是dll本身的问题了。
      

  8.   

    编译没报错,只能说明是整个模块没有语法错误。
    但并不代表这个代码执行时不会引起进程的异常(当然,也许你的代码真的没有问题)。
    你可以先在 VC 中新建一个工程对你的 dll 进行一次测试,如果没有问题,再考虑为什么在 VB 中会出问题吧!
      

  9.   

    很简单,vb生成exe,在vc中调试即可发现问题所在.
      

  10.   

    写完整试试?
    Private Declare Function Start Lib "VcleD.dll" (ByVal CfgFile As String) As Long
    加上完整路径再试试?
    Private Declare Function Start Lib "d:\VcleD.dll" (ByVal CfgFile As String) As Long