在VC程序中定义一个*.def文件。包含Test的输出。unsigned short __declspec(dllexport) Test(LPSTR Password, long nMaxBufs) { if (strlen("abcdef") > nMaxBufs) strcpy(Password, "abcdef"); else return -1; return 1; }VB代码如下: Private Declare Function Test Lib "password.dll" (sss As String, nMaxBufs as long) As Integer dim nn as Integer dim ss as string, ts as string ss = space(100) nn = Test(ss, 100) ss = left(ss, InStr(1, ss, vbnullstring))
unsigned short __declspec(dllexport) Test函数输出使用 stdcall 关键字函数声明应该如下:unsigned short _stacall __declspec(dllexport) test(LPCTSTR ss)参数类型为 LPCTSTR 就可以了
抱歉应该为__stdcall 关键字应为程序编译时缺省用的为 __cdecl
Private Declare Function Test Lib "password.dll" (byval sss As String) As long ---------------------------------------------------- 在VB中必须把字符串定义为:byval类型,返回类型为LONG
{
if (strlen("abcdef") > nMaxBufs)
strcpy(Password, "abcdef");
else
return -1;
return 1;
}VB代码如下:
Private Declare Function Test Lib "password.dll" (sss As String, nMaxBufs as long) As Integer
dim nn as Integer
dim ss as string, ts as string
ss = space(100)
nn = Test(ss, 100)
ss = left(ss, InStr(1, ss, vbnullstring))
if (strlen("abcdef") < nMaxBufs)
strcpy(Password, "abcdef");
else
return -1;
return 1;
----------------------------------------------------
在VB中必须把字符串定义为:byval类型,返回类型为LONG