Active DLL中如何传递"用户自定义类型",高人Help Me.
由于我要向一个类中传递很多参数,这些参数可以分成几组.
如果参数一个一个的传递,显得程序有一些凌乱。
我就想到WIN32 API中的参数经常是一个"结构",也就是VB
所说的"用户自定义类型",只要把结构变量的值赋好就可以了。
这样让别人使用这个类时,就很方便,我也很容易写这个类
的使用说明。
下面是我想完成这个功能而写的类和测试工程。愿大家给出解决的方法。
'Class1.cls
Option Explicit
Private Type uS
cf(2, 4) As Double
intFlag As Integer
strname As String
End Type
Private usAA As uS
Public Property Let XS(ByRef s As Variant)
Dim i As Integer, j As Integer
For i = 0 To 2
For j = 0 To 4
usAA.cf(i, j) = s.cf(i, j)
Next j
Next i
usAA.intFlag = s.intFlag
usAA.strname = s.strname
End Property
Public Function funPrint()
Dim i As Integer, j As Integer
For i = 0 To 2
For j = 0 To 4
Debug.Print usAA.cf(i, j)
Next j
Next i
Debug.Print usAA.intFlag
Debug.Print usAA.strname
End Function
'测试工程
'module1.bas
Option Explicit
Public Type uS
cf(2, 4) As Double
intFlag As Integer
strname As String
End Type
Public usAA As uS
'form1.frm
Option Explicit
Dim clstest As New Class1
Private Sub Command1_Click()
usAA.cf(0, 0) = 1
usAA.intFlag = 5
usAA.strname = "OK"
clstest.XS (usAA)
clstest.funPrint
End Sub