我用vb调用c DLL的函数,DLL的两个出口函数如下:
bool _stdcall cleanuparray(char InBuffer[],int MaxSize)
{
int i;
memset(InBuffer,0,MaxSize);
for(i = 0; i < MaxSize; i++)
InBuffer[i] = 'a';
return false;}bool _stdcall mytest(char InBuffer[],int MaxSize)
{
return false;
}
vb的声明:
Declare Function cleanuparray Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Boolean
Declare Function mytest Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Booleanvb程序如下:
x = cleanuparray(ab(0), MaxSize)
If x Then
MsgBox "x is true"
Else
MsgBox "x is false"
End If
y = mytest(ab(0), MaxSize)
If y Then
MsgBox "y is true"
Else
MsgBox "y is false"
End If
很奇怪的问题就是,“x is false”“y is true”,从DLL函数可以看出,两个函数不管什么情况下都返回false的。
而改用这种表达方式:
x = cleanuparray(ab(0), MaxSize)
If x = True Then
MsgBox "x is true"
Else
MsgBox "x is false"
End If
y = mytest(ab(0), MaxSize)
If y = True Then
MsgBox "y is true"
Else
MsgBox "y is false"
End If
结果却正确了:"x is false","y is false"
if x then
跟if x=true then两者有这么大的区别吗?!更诡异的是
我把vb声明改为:
Declare Function cleanuparray Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Long
Declare Function mytest Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Long
的时候,
昨天晚上用if y then,if y=true then(包括x)判断都正确,
今天早上起来,同样的情况下,if y then 却判断失常了,y好像总是true(其实肯定返回false)。我不明白,为什么if x then总能判断正确,而if y then却会失常?高手指点,谢谢!!
bool _stdcall cleanuparray(char InBuffer[],int MaxSize)
{
int i;
memset(InBuffer,0,MaxSize);
for(i = 0; i < MaxSize; i++)
InBuffer[i] = 'a';
return false;}bool _stdcall mytest(char InBuffer[],int MaxSize)
{
return false;
}
vb的声明:
Declare Function cleanuparray Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Boolean
Declare Function mytest Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Booleanvb程序如下:
x = cleanuparray(ab(0), MaxSize)
If x Then
MsgBox "x is true"
Else
MsgBox "x is false"
End If
y = mytest(ab(0), MaxSize)
If y Then
MsgBox "y is true"
Else
MsgBox "y is false"
End If
很奇怪的问题就是,“x is false”“y is true”,从DLL函数可以看出,两个函数不管什么情况下都返回false的。
而改用这种表达方式:
x = cleanuparray(ab(0), MaxSize)
If x = True Then
MsgBox "x is true"
Else
MsgBox "x is false"
End If
y = mytest(ab(0), MaxSize)
If y = True Then
MsgBox "y is true"
Else
MsgBox "y is false"
End If
结果却正确了:"x is false","y is false"
if x then
跟if x=true then两者有这么大的区别吗?!更诡异的是
我把vb声明改为:
Declare Function cleanuparray Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Long
Declare Function mytest Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Long
的时候,
昨天晚上用if y then,if y=true then(包括x)判断都正确,
今天早上起来,同样的情况下,if y then 却判断失常了,y好像总是true(其实肯定返回false)。我不明白,为什么if x then总能判断正确,而if y then却会失常?高手指点,谢谢!!
Declare Function cleanuparray Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Long
Declare Function mytest Lib "mydll.dll" (InBuffer As Byte, ByVal MaxSize As Long) As Long
x = cleanuparray(ab(0), MaxSize)
If x <> 0 Then
MsgBox "x is true"
Else
MsgBox "x is false"
End If
y = mytest(ab(0), MaxSize)
If y <> 0 Then
MsgBox "y is true"
Else
MsgBox "y is false"
End If
x = cleanuparray(ab(0), MaxSize)
MsgBox "x is " & xy = mytest(ab(0), MaxSize)
MsgBox "y is " & y
照你的
x = cleanuparray(ab(0), MaxSize)
MsgBox "x is " & xy = mytest(ab(0), MaxSize)
MsgBox "y is " & y
改动后,
总是y is true难道是我dll的函数总是返回true了?!但是我用If y = True Then的表达方式,
y是false的怎么解释?