Sample: DispInvoker.exe Calls Automation Methods Passing Names at Run-TimeID: Q202057
|
DispInvoker.exe is a self-extracting executable file that provides functionality similar to the Visual Basic 6.0 CallByName function. Most of the time you can discover the properties and methods of an object at design-time and write code to handle them. In a few cases, however, you may not know about an object’s properties and methods in advance, or you may simply want the flexibility of allowing an end user to specify properties or execute methods at run-time. Visual Basic 6.0 introduced the CallByName function to provide this functionality, but it is not available in earlier versions of Visual Basic. The Dispinvoker sample provides similar functionality, allowing you to create a wrapper object with:
The following file is available for download from the Microsoft
Software Library:
DispInvoker.exeRelease Date: Apr-14-1999
Q119591 How to Obtain Microsoft Support Files from Online Services
Automation allows calling objects in three ways:
File Name File Size class1 1KB DispTools.aps 4KB DispTools.clw 1KB DispTools.cpp 4KB DispTools.def 1KB DispTools.dll 74KB DispTools.dsp 17KB DispTools.dsw 1KB DispTools.h 7KB DispTools.idl 1KB DispTools.ncb 153KB DispTools.opt 55KB DispTools.plg 4KB DispTools.rc 4KB DispTools.tlb 2KB DispTools_i.c 2KB DispTools_p.c 7KB DispToolsps.def 1KB DispToolsps.mk 1KB dlldata.c 1KB dlldatax.c 1KB form1 3KB lUnklmpl.cpp 1KB lUnklmpl.h 1KB lUnklmpl.rgs 1KB module1 1KB Mssccprj 1KB Project1 22KB Project1 1KB resource.h 1KB StdAfx.cpp 1KB StdAfx.h 1KB Wrap.cpp 2KB Wrap.h 5KB Wrap.rgs 1KB
Set objWrap = Wrap.GetInvoker(obj)
objWrap has the same methods as obj plus the additional method Call(), which allows full use of late binding.
' Create an object of type class1
Dim obj As New Class1
Dim wrp as New DISPTOOLSLib.Wrap
Dim objWrp As Object
' Retrieve the DispInvoker wrapper
Set objWrp = wrp.GetInvoker(obj)
obj.mySub ' Calls method mySub directly on the object obj.
objWrp.mySub ' Calls method mySub on the DispInvoker wrapper ObjWrp.
objWrp.Call("mySub") ' Calls method mySub using Call() method on the
' DispInvoker wrapper.
'--------------------------------
Running the preceding code does the following:
Additional query words:
Keywords : kbfile kbActiveX kbCOMt kbVBp400 kbVBp500 kbGrpVB
Version : WINDOWS:4.0,5.0
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: April 14, 1999