在VC中我做了一个API函数给VB调用:VC:代码片断:typedef struct S_LOG
{
char* LogDateTime;
int UserID;
int Code;
int Val;
int Spare;
} LOG;
int WINAPI GetLog(int MachineID,int* LogNumber,S_LOG* pLog)
{
if(m_pComm==NULL)
{
return COMM_FAILURE;
}
char chSend[10]; //令牌报文
int i;
//cData[0]=LOBYTE(i); //取低位
//cData[1]= HIBYTE(i); //取高位 memset(chSend,0,sizeof(chSend));
*LogNumber=10;
for(i=0;i<10;i++)
{
pLog->Code=1;
pLog->LogDateTime="2002-10-10 12:08:23";
pLog->Spare=0;
pLog->Val=0;
pLog->UserID=3000+i;
pLog++;
}
return COMM_SUCCESS;
}
VB代码
Public Declare Function GetLog Lib "E:\MYWORK\指纹通讯开发包\API实现包\FingerComm\Debug\FingerComm.dll" (ByVal MachineID As Integer, ByRef LogNumber As Integer, ByRef LogInfo As Any) As IntegerType S_LOG
LogDateTime As String
UserID As Integer
Code As Integer
Val As Integer
Spare As Integer
End TypePrivate Sub Command2_Click()
Dim Log(10) As S_LOG
Dim i As Integer
Dim iRes As Integer
iRes = OpenComm(2, 9600)
If iRes = 1 Then
iRes = GetLog(1, i, Log(0))
MsgBox Log(0).LogDateTime
CloseComm
End If
End SubVB代码我想得到Log(10)每个单元的值
VC中单步调试FOR循环中已经没有错在return COMM_SUCCESS;后报错,VB程序关闭,提示unhandled execption.....access voilation
{
char* LogDateTime;
int UserID;
int Code;
int Val;
int Spare;
} LOG;
int WINAPI GetLog(int MachineID,int* LogNumber,S_LOG* pLog)
{
if(m_pComm==NULL)
{
return COMM_FAILURE;
}
char chSend[10]; //令牌报文
int i;
//cData[0]=LOBYTE(i); //取低位
//cData[1]= HIBYTE(i); //取高位 memset(chSend,0,sizeof(chSend));
*LogNumber=10;
for(i=0;i<10;i++)
{
pLog->Code=1;
pLog->LogDateTime="2002-10-10 12:08:23";
pLog->Spare=0;
pLog->Val=0;
pLog->UserID=3000+i;
pLog++;
}
return COMM_SUCCESS;
}
VB代码
Public Declare Function GetLog Lib "E:\MYWORK\指纹通讯开发包\API实现包\FingerComm\Debug\FingerComm.dll" (ByVal MachineID As Integer, ByRef LogNumber As Integer, ByRef LogInfo As Any) As IntegerType S_LOG
LogDateTime As String
UserID As Integer
Code As Integer
Val As Integer
Spare As Integer
End TypePrivate Sub Command2_Click()
Dim Log(10) As S_LOG
Dim i As Integer
Dim iRes As Integer
iRes = OpenComm(2, 9600)
If iRes = 1 Then
iRes = GetLog(1, i, Log(0))
MsgBox Log(0).LogDateTime
CloseComm
End If
End SubVB代码我想得到Log(10)每个单元的值
VC中单步调试FOR循环中已经没有错在return COMM_SUCCESS;后报错,VB程序关闭,提示unhandled execption.....access voilation
毕竟VC与VB在语言上有很多差异,包括
参数入栈,地址引用等都会不同,这样做不安全,也不推荐
最好使用语言无关接口,例如COM方式实现
vb里面的String与Windows基本数据类型BSTR对应的。