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
程序总是提示调用约定错误。相关代码: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
其中只有 server是输出用的
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估计你就不会调用约定错误了....
谢谢楼上,晚上试试.另外,C函数原型为: int SLN_GetConfigFromTextFile(char*, char*, char* char*);
定义足够长度的字符串 例如:Dim Name As String*255
用它来试试: Private Declare Sub InitName Lib "Compy.dll" (ByRef strName() As Byte, ByRef strVer() As Byte)
///////////////////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的方式输出函数的,所以名字上不会改变。调用成功
Dim strName As String * 256
Dim strVer As String * 256
InitName strName, strVer
MsgBox strName, vbOKOnly, strVer
End Sub
{
strcpy(name,"渊海易乐");
strcpy(ver,"VER 1.105");
}
(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
(ByVal fileName As String, _
ByVal path As String, _
ByVal key As String, _
ByVal value As String) As LONG用Long而不是Integer估计你就不会调用约定错误了....
int SLN_GetConfigFromTextFile(char*, char*, char* char*);
例如:Dim Name As String*255
Private Declare Sub InitName Lib "Compy.dll" (ByRef strName() As Byte, ByRef strVer() As Byte)
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的方式输出函数的,所以名字上不会改变。调用成功
改成LONG也不行。TO:51365133(渊海)
形式上我的和你的没有什么大差别,但就是不成功。同一个DLL中另一个函数(参数也全是char*,不过只是输入用)却可以成功
{
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