我用VB做了一个DLL文件,其中有一个函数的一个参数是数组,
我如此声明:
byref sz() as string
当向此DLL传递一个string型的数组时,传递过去的数组读取出来却是问号...
不知道如何向DLL传递字符串型数组???希望能给出个简单的例子...
我如此声明:
byref sz() as string
当向此DLL传递一个string型的数组时,传递过去的数组读取出来却是问号...
不知道如何向DLL传递字符串型数组???希望能给出个简单的例子...
For i = 1 To UBound(sz)
If Len(sz(i)) > 0 Then
MsgBox sz(i)
End If
NextEnd FunctionPublic Function DLLMain(ByVal hInstDLL As Long, ByVal fdwReason As Long, ByVal lpwReserved As Long) As Long
DLLMain = 1 '这是一个DLL的基本过程,在装载和卸载DLL时都会调用
End FunctionPublic Sub Main()
'这是VB的主过程,这里的目的是使VB可以顺利进行编译
'End Sub 这个结束在键入时VB会自动插入End Sub
调用DLL的程序代码:Private Declare Function guolv Lib "guolv.dll" (ByRef sz() As String) As LongPublic sz() As StringPrivate Sub Command1_Click()
Dim j As IntegerFor j = 1 To 10
sz(j) = ""
NextFor i = 1 To List1.ListCount
sz(i) = List1.List(i - 1)
Next
guolv sz()
End Sub
楼主不定义sz()的具体长度,在
For j = 1 To 10
sz(j) = ""
Next
能运行的通吗?
你不妨用redim preserve 试试
Dim j As IntegerFor j = 1 To 10
sz(j) = ""
NextFor i = 1 To List1.ListCount
sz(i) = List1.List(i - 1)
Next
guolv sz()
End Sub
问题出在,DLL的那代码是作为DLL时,调用程序调用起DLL来就发现有问题.
在 guolv 中用 MsgBox strconv(sz(i),vbunicode) 试试成不成?