我的VC6 DLL 接口代码如下:#pragma pack(1)typedef struct
{
char szServerName[33];
int nProtocal;
char szAddress[33];
int nPort;
char szSendName[33];
char szReceiveName[33];
}
tagConnectOption;extern "C" __declspec(dllexport) int __stdcall SetConnectOption(void * hHandle, tagConnectOption stConnection)
{
printf("szServerName=%s", stConnection.szServerName);
printf("nProtocal=%d", stConnection.nProtocal);
printf("szAddress=%s", stConnection.szAddress);
printf("nPort=%d", stConnection.nPort);
printf("szSendName=%s", stConnection.szSendName);
printf("szReceiveName=%s", stConnection.szReceiveName);
return 1;
}DEF 文件定义如下:LIBRARY test
EXPORTS
SetConnectOption @1我现在需要在 VB6 调用 SetConnectOption 函数,请问我该怎么调用与送结构体中的每一个值?
现在我的想法是这样
Private Type tagConnectOption
szServerName(33) As Byte
nProtocal As Long
szAddress(33) As Byte
nPort As Long
szSendName(33) As Byte
szReceiveName(33) As Byte
End TypePrivate Declare Function SetConnectOption Lib "test.dll" (stConnection As tagConnectOption) As Long但我该具体赋值呢 总是不行 大家知道的麻烦一起想想办法。
{
char szServerName[33];
int nProtocal;
char szAddress[33];
int nPort;
char szSendName[33];
char szReceiveName[33];
}
tagConnectOption;extern "C" __declspec(dllexport) int __stdcall SetConnectOption(void * hHandle, tagConnectOption stConnection)
{
printf("szServerName=%s", stConnection.szServerName);
printf("nProtocal=%d", stConnection.nProtocal);
printf("szAddress=%s", stConnection.szAddress);
printf("nPort=%d", stConnection.nPort);
printf("szSendName=%s", stConnection.szSendName);
printf("szReceiveName=%s", stConnection.szReceiveName);
return 1;
}DEF 文件定义如下:LIBRARY test
EXPORTS
SetConnectOption @1我现在需要在 VB6 调用 SetConnectOption 函数,请问我该怎么调用与送结构体中的每一个值?
现在我的想法是这样
Private Type tagConnectOption
szServerName(33) As Byte
nProtocal As Long
szAddress(33) As Byte
nPort As Long
szSendName(33) As Byte
szReceiveName(33) As Byte
End TypePrivate Declare Function SetConnectOption Lib "test.dll" (stConnection As tagConnectOption) As Long但我该具体赋值呢 总是不行 大家知道的麻烦一起想想办法。
extern "C" __declspec(dllexport) int __stdcall SetConnectOption(tagConnectOption stConnection)
首先必须改成 tagConnectOption *stConnection 参数。
原型函数不是 2 个参数吗?Private Declare Function SetConnectOption Lib "test.dll" (stConnection As tagConnectOption) As Long你的参数却只有一个,试试是不是缺少参数的问题
我不会c,如果函数确实要求将整个结构直接传过去,那就把声明改掉
结构肯定一般都是4字节对齐的
Private Declare Function SetConnectOption Lib "test.dll" ( a as long ,byval p1 As long , byval p2 as long,byval p3 as long ,byval p4..pn.. as long ) As Long先获取这样一个值: ParamCount = lenb(tagConnectOption) \ 4
调用时:
dim Params() as long
redim Params(ParamCount-1)
call SetConnectOption a,params(0),params(1),params(2....n)
以上方法,针对直接传送结构内容的方式
参数 lpFindFileData 前面是带lp的,在DLL内部是一个批示指针,即结构体地址。
Private Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" (ByVal lpFileName As String, ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
ParamCount = lenb(tagConnectOption) \ 4
redim Params(ParamCount-1)
copymemory params(0),tagConnectOption,lenb(tagConnectOption)
call SetConnectOption a,params(0),params(1),params(2....n)
注意把函数体中stConnection改为指针调用的形式vb
Private Declare Function SetConnectOption Lib "test.dll" (Byref stConnection As tagConnectOption) As Long