我用VC开发了一个常规动态连接库.
申明如下: 
extern "C" __declspec(dllexport) char* GetBalance(char*SN)在VB中我是如下用的:
...
Private Declare Function GetBalance Lib "D:\TestDll\VB6\CustComm.dll" (sn As String) As String
...在按钮的事件中:
    Dim result As String
    result = GetBalance("0000-00-0200-00098") //此语句报错
...大侠们 help.

解决方案 »

  1.   

    Dim result As String*10
      

  2.   

    vc中声名的字符串在vb中调用的时候要规定长度
      

  3.   

    Private Declare Function GetBalance Lib "D:\TestDll\VB6\CustComm.dll" (ByVal sn As String) As String
    需要指定传值方式。
      

  4.   

    dim result as string * 255result=string(255," ")
    result = GetBalance("0000-00-0200-00098") 
      

  5.   

    一VC的DLL
    1.*.cpp
    EXTERN_C BSTR WINAPI RegisterVB(char*SN)//注册
    {
    return (BSTR)Register(SN);
    }
    EXTERN_C BSTR WINAPI GetBalanceVB(char*SN)//余额
    {
    return (BSTR)GetBalance(SN);
    }
    EXTERN_C BSTR WINAPI SendSMSVB(char*SN,char*MobileNum,char*Content)//发送短信(即时)
    {
    return (BSTR)SendSMS(SN,MobileNum,Content);
    }
    EXTERN_C BSTR WINAPI SendScheSMSVB(char*SN,char*MobileNum,char*Content,char *SendTime)//发送短信(定时)
    {
    return (BSTR)SendScheSMS(SN,MobileNum,Content,SendTime);
    }
    EXTERN_C BSTR WINAPI ReceiveSMSVB(char*SN) //接收
    {
    return (BSTR)ReceiveSMS(SN);
    }
    EXTERN_C BSTR WINAPI ChargeUpVB(char*SN,char*Acco,char*Pass)//存值
    {
    return (BSTR)ChargeUp(SN,Acco,Pass);
    }
    EXTERN_C BSTR WINAPI GetPriceVB(char*SN)//价格
    {
    return (BSTR)GetPrice(SN);
    }
    EXTERN_C BSTR WINAPI GetCopyrightVB()//版权
    {
    return (BSTR)GetCopyright();
    }
    EXTERN_C BSTR WINAPI GetAuthorVB()//作者
    {
    return (BSTR)GetAuthor();
    }
    EXTERN_C BSTR WINAPI GetSoftVerVB()//版本
    {
    return (BSTR)GetSoftVer();
    }
    EXTERN_C BSTR WINAPI GetProgLanguageVB()//设计语言
    {
    return (BSTR)GetProgLanguage();
    }
    2.*.def
    LIBRARY      "MyComm3.dll"EXPORTS
    GetPriceVB @1
    GetBalanceVB @2
    SendSMSVB @3
    SendScheSMSVB @4
    RegisterVB @5
    ChargeUpVB @6
    ReceiveSMSVB @7
    GetCopyrightVB @8
    GetAuthorVB @9
    GetSoftVerVB @10
    GetProgLanguageVB @11
    二VB的调用代码
    1、申明
    Option Explicit
    Private Declare Function GetPriceVB Lib "CustComm" (ByVal sn As String) As String
    Private Declare Function GetBalanceVB Lib "CustComm" (ByVal sn As String) As StringPrivate Declare Function SendSMSVB Lib "CustComm" (ByVal sn As String, ByVal mn As String, ByVal ct As String) As String
    Private Declare Function SendScheSMSVB Lib "CustComm" (ByVal sn As String, ByVal mn As String, ByVal ct As String, ByVal ti As String) As String
    Private Declare Function RegisterVB Lib "CustComm" (ByVal sn As String) As String
    Private Declare Function ChargeUpVB Lib "CustComm" (ByVal sn As String, ByVal acco As String, ByVal pass As String) As String
    Private Declare Function ReceiveSMSVB Lib "CustComm" (ByVal sn As String) As String
    Private Declare Function GetCopyrightVB Lib "CustComm" () As String
    Private Declare Function GetAuthorVB Lib "CustComm" () As String
    Private Declare Function GetSoftVerVB Lib "CustComm" () As String
    Private Declare Function GetProgLanguageVB Lib "CustComm" () As String2.调用
    Private Sub Command3_Click()
        '余额
        Dim result As String
        result = GetBalanceVB("0000-00-0200-00098")
        If ((result = "998") Or (result = "")) Then
            MsgBox ("网络故障")
        ElseIf (result = "999") Then
            MsgBox ("网络故障或其它故障")
        Else
            result = Trim(result) & "元"
            MsgBox (result)
        End If
        'Text1.Text = StrConv(TempBytes, vbUnicode)
    End Sub