这个DLL中有一个函数的参数是char*,通过它返回一个字符串,在VB中,声明API时,如果声明为byref str as String,则程序运行出现异常,但声明为byval as String又不可能取出这个数据,请问应当如何处理才能取得由char*返回的数据呢?

解决方案 »

  1.   

    Dim strName As String * 256
      

  2.   

    Private Declare Sub InitName Lib "Compy.dll" (ByVal strName As String, ByVal strVer As String)Private Sub Command1_Click()
     Dim strName As String * 256
     Dim strVer As String * 256
     InitName strName, strVer
     MsgBox strName, vbOKOnly, strVer
    End Sub
      

  3.   

    #include <string.h>void InitName(char * name,char * ver)
    {
    strcpy(name,"渊海易乐");
    strcpy(ver,"VER 1.105");
    }
      

  4.   

    程序总是提示调用约定错误。相关代码:Private Declare Function SLN_GetConfigFromTextFile Lib "slnsoftconfigfile.dll" _
        (ByVal fileName As String, _
        ByVal path As String, _
        ByVal key As String, _
        ByVal value As String) As IntegerConst CONFIGFILE = "dbconfig.ini"       '配置文件名
    Const DBROOT = "dbroot"                 '数据库配置项根
    Const DBSERVER = "server"               '服务器配置项名
    Const DBACCOUNT = "account"             '服务器登录帐号配置项名
    Const DBPWD = "pwd"                     '服务器登录密码配置项名
    Const DATABASENAME = "dbname"           '数据库名配置项名Private server As String * 256      '数据库服务器SLN_GetConfigFromTextFile CONFIGFILE, DBROOT, DBSERVER, server
      

  5.   

    其中只有 server是输出用的
      

  6.   

    Private Declare Function SLN_GetConfigFromTextFile Lib "slnsoftconfigfile.dll" _
        (ByVal fileName As String, _
        ByVal path As String, _
        ByVal key As String, _
        ByVal value As String) As LONG用Long而不是Integer估计你就不会调用约定错误了....
      

  7.   

    谢谢楼上,晚上试试.另外,C函数原型为:
    int SLN_GetConfigFromTextFile(char*, char*, char* char*);
      

  8.   

    定义足够长度的字符串
    例如:Dim Name As String*255
      

  9.   

    用它来试试:
    Private Declare Sub InitName Lib "Compy.dll" (ByRef strName() As Byte, ByRef strVer() As Byte)
      

  10.   

    ///////////////////VB调用方式
    Private Declare Sub InitName Lib "Compy.dll" (ByVal strName As String, ByVal strVer As String)Private Sub Command1_Click()
     Dim strName As String * 256
     Dim strVer As String * 256
     InitName strName, strVer
     MsgBox strName, vbOKOnly, strVer
    End Sub
    ////////////////VC函数原型#include <string.h>void InitName(char * name,char * ver)
    {
    strcpy(name,"渊海易乐");
    strcpy(ver,"VER 1.105");
    }我用的是.def的方式输出函数的,所以名字上不会改变。调用成功
      

  11.   

    TO:supergreenbean(超级绿豆(MS MVP - VB) - 春天,什么都发~了)
    改成LONG也不行。TO:51365133(渊海) 
    形式上我的和你的没有什么大差别,但就是不成功。同一个DLL中另一个函数(参数也全是char*,不过只是输入用)却可以成功
      

  12.   

    void __stdcall InitName(char * name,char * ver)
    {
    strcpy(name,"渊海易乐");
    strcpy(ver,"VER 1.105");
    }
    =>
    Private Declare Sub InitName Lib "Compy.dll" (ByVal strName As String, ByVal strVer As String)int __stdcall SLN_GetConfigFromTextFile(char*, char*, char* char*);
    =>
    Private Declare Function SLN_GetConfigFromTextFile Lib "slnsoftconfigfile.dll" _
        (ByVal fileName As String, _
        ByVal path As String, _
        ByVal key As String, _
        ByVal value As String) As LONG