向DLL模块传递数组一般用byref,而且使用的参数为该数组的第一个参数。 如 dim intTest(0 to 9) as Integer FunctionTest(intTest(0)) 这样的声明不正确吧, declare Function Calculate(Value as double,ValueName as double,str as string) CString str是一个MFC中的字符串类型的变量,str as string是一个BSTR类型的变量。
Function GetCharByte(ByVal OneChar As Integer, ByVal IsHighByte As Boolean) As Byte ' 该函数获得一个字符的高字节或低字节 If IsHighByte Then If OneChar >= 0 Then GetCharByte = CByte(OneChar \ 256) '右移8位,得到高字节 Else GetCharByte = CByte((OneChar And &H7FFF) \ 256) Or &H80 End If Exit Function Else GetCharByte = CByte(OneChar And &HFF) '屏蔽掉高字节,得到低字节 Exit Function End If End FunctionSub StrToByte(StrToChange As String, ByteArray() As Byte) '该函数将一个字符串转换成字节数组 Dim LowBound, UpBound As Integer Dim i, count, length As Integer Dim OneChar As Integercount = 0 length = Len(StrToChange) LowBound = LBound(ByteArray) UpBound = UBound(ByteArray)For i = LowBound To UpBound ByteArray(i) = 0 '初始化字节数组 NextFor i = LowBound To UpBound count = count + 1 If count <= length Then OneChar = Asc(Mid(StrToChange, count, 1))If (OneChar > 255) Or (OneChar < 0) Then '该字符是非ASCII字符 ByteArray(i) = GetCharByte(OneChar, True) '得到高字节 i = i + 1 If i <= UpBound Then ByteArray(i) = GetCharByte(OneChar, False) '得到低字节 Else '该字符是ASCII字符 ByteArray(i) = OneChar End If Else Exit For End If Next End SubSub ChangeStrAryToByte(StrAry() As String, ByteAry() As Byte) '将字符串数组转换成字节数组 Dim LowBound, UpBound As Integer Dim i, count, StartPos, MaxLen As Integer Dim TmpByte() As ByteLowBound = LBound(StrAry) UpBound = UBound(StrAry) count = 0 ReDim ByteAry(0)For i = LowBound To UpBound MaxLen = LenB(StrAry(i)) ReDim TmpByte(MaxLen + 1) ReDim Preserve ByteAry(count + MaxLen + 1) Call StrToByte(StrAry(i), TmpByte) '转换一个字符串 StartPos = count Do ByteAry(count) = TmpByte(count - StartPos) count = count + 1 If ByteAry(count - 1) = 0 Then Exit Do Loop '将每一个字符串对应 的字节数组按顺序填入结果数组中 ReDim Preserve ByteAry(count - 1) Next i End Sub
如
dim intTest(0 to 9) as Integer
FunctionTest(intTest(0))
这样的声明不正确吧,
declare Function Calculate(Value as double,ValueName as double,str as string)
CString str是一个MFC中的字符串类型的变量,str as string是一个BSTR类型的变量。
这个和指针很类似,用byref传递,并且要声明数组,楼上的兄弟说得
没错
If IsHighByte Then
If OneChar >= 0 Then
GetCharByte = CByte(OneChar \ 256)
'右移8位,得到高字节
Else
GetCharByte = CByte((OneChar
And &H7FFF) \ 256) Or &H80
End If
Exit Function
Else
GetCharByte = CByte(OneChar And &HFF)
'屏蔽掉高字节,得到低字节
Exit Function
End If
End FunctionSub StrToByte(StrToChange As String, ByteArray() As Byte)
'该函数将一个字符串转换成字节数组
Dim LowBound, UpBound As Integer
Dim i, count, length As Integer
Dim OneChar As Integercount = 0
length = Len(StrToChange)
LowBound = LBound(ByteArray)
UpBound = UBound(ByteArray)For i = LowBound To UpBound
ByteArray(i) = 0 '初始化字节数组
NextFor i = LowBound To UpBound
count = count + 1
If count <= length Then
OneChar = Asc(Mid(StrToChange, count, 1))If (OneChar > 255) Or (OneChar < 0) Then
'该字符是非ASCII字符
ByteArray(i) = GetCharByte(OneChar, True) '得到高字节
i = i + 1
If i <= UpBound Then ByteArray(i)
= GetCharByte(OneChar, False)
'得到低字节
Else
'该字符是ASCII字符
ByteArray(i) = OneChar
End If
Else
Exit For
End If
Next
End SubSub ChangeStrAryToByte(StrAry()
As String, ByteAry() As Byte)
'将字符串数组转换成字节数组
Dim LowBound, UpBound As Integer
Dim i, count, StartPos, MaxLen As Integer
Dim TmpByte() As ByteLowBound = LBound(StrAry)
UpBound = UBound(StrAry)
count = 0
ReDim ByteAry(0)For i = LowBound To UpBound
MaxLen = LenB(StrAry(i))
ReDim TmpByte(MaxLen + 1)
ReDim Preserve ByteAry(count + MaxLen + 1)
Call StrToByte(StrAry(i), TmpByte) '转换一个字符串
StartPos = count
Do
ByteAry(count) = TmpByte(count - StartPos)
count = count + 1
If ByteAry(count - 1) = 0 Then Exit Do
Loop '将每一个字符串对应
的字节数组按顺序填入结果数组中
ReDim Preserve ByteAry(count - 1)
Next i
End Sub
下面看一个转换的例子:DimResultAry()asByte
DimSomeStr(2)asString
SomeStr(0)="测试1"
SomeStr(1)="测试222"
SomeStr(2)="测试33"
CallChangeStrAryToByte
(SomeStr,ResultAry)'转换字符串数组
再建立一个Long数组,把它的每一个元素设为StrPtr(字符串数组的元素)
把那个Long数组传过去就行了