我用这段代码(VB.NET)编写了一个 COM-Visible DLL
' .NET Class with implementing an interface to make it visible
Public Class VisibleClass
Public Sub callableSub(ByVal names As ACustomCollection, _
Optional ByVal doSomething As Boolean = True) _
Implements IVisibleClass.visibleCallableSub
Me.doSub(names.process, doSomething)
End Sub
End Class
' Interface for COM-visibility
<InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IVisibleClass
Sub visibleCallableSub(ByVal names As ACustomCollection, _
Optional ByVal doSomething As Boolean = True)
End Interface
这也是创建对象并调用其方法的 ASP 网页:
' stuff.asp
Dim visibleObject
Dim aCustomCollection
Set visibleObject = getNewVisibleInstance (aCollection)
Set aCustomCollection = createEmptyCollection
aCustomCollection.add someStuffs
aCustomCollection.add otherStuffs
aCustomCollection.add lastStuffs
' These calls work:
visibleObject.visibleCallableSub(aCustomCollection)
visibleObject.visibleCallableSub(aCustomCollection), False
visibleObject.visibleCallableSub(aCustomCollection), True
Call document.fetchPropertyCollection ((properties), false)
' These ones don't:
visibleObject.visibleCallableSub someparams
visibleObject.visibleCallableSub someparams, False
visibleObject.visibleCallableSub someparams, True
Call document.fetchPropertyCollection (properties, false)
非工作调用会产生以下错误:
无效的过程调用或参数
我不明白为什么我必须加上括号。我知道这告诉口译员在传递主题之前制作副本,但不是为什么它是强制性的。
注意: 这与这个问题相同,即关于在需要副本的地方传递引用。然而,这个问题被告知是因为“传递另一个函数的返回值”,这使得通过研究更难达到。