Repository navigation
CDispInvoke
Home › All Categories › sys/win › sys/win/com › CDispInvoke
Calls the methods and properties of a COM Automation object by name.
Automation objects (the scripting runtime, the shell, Office, WMI …) implement IDispatch: a
caller looks a member up by name, gets back a number for it (a DISPID) and calls it with its
arguments packed as VARIANTs. This is late binding, the way script languages talk to COM, and it
needs no interface declarations. CDispInvoke does the packing: you name the member and pass
DVARIANTs, or plain literals and numbers that turn into them, and get a DVARIANT
back.
The model to keep in mind:
-
It holds one reference.
CDispInvokekeeps the object'sIDispatchpointer inm_pDispand releases it in its destructor. A property or method that returns an object gives aDVARIANTholding it; assign that to anotherCDispInvoketo call into it. -
It initialises COM. Every constructor calls
CoInitialize( NULL )and the destructor callsCoUninitialize()to match, so a program that only usesCDispInvokeneeds neither. One that callsCoInitializeitself must destroy itsCDispInvokes beforeCoUninitialize. -
Creating an object from a ProgID (
"Scripting.Dictionary") keeps the pointer the object returns forIUnknownand does not ask it forIDispatch. For most scripting objects the two are the same; for some,WScript.Shellamong them, they are not, and the first call crashes. Create those from their CLSID instead, which asks forIDispatch: see Constructor. -
Errors are reported, not raised. Each call stores its
HRESULT; GetLastResult returns it and GetErrorInfo describes it. A failed call returns an emptyDVARIANT. -
Arguments are given in order, first to last, and reversed for
IDispatchinternally.Invoketakes up to 16,Get2,Set4,SetRef3 andPutandPutRefone. To leave out an optional argument in the middle, pass aDVARIANTof typeVT_ERRORholdingDISP_E_PARAMNOTFOUND.
#import "sys/win"
#import "sys/win/com"
using win, comCalls methods of the scripting runtime's FileSystemObject, reads an error, and uses
WScript.Shell and the object one of its properties returns:
#import "sys/win"
#import "sys/win/com"
using win, com
function main() as long
CoInitialize( NULL )
scope
' Methods that take and return strings
dim fso as CDispInvoke = "Scripting.FileSystemObject"
if fso.IsObject() then
print fso.Invoke( "BuildPath", "C:\Reports", "summary.txt" ).ToStr()
print fso.Invoke( "GetExtensionName", "notes.final.docx" ).ToStr()
' Errors are reported, not raised
fso.Invoke( "NoSuchMethod" )
print fso.GetErrorInfo()
end if
' WScript.Shell is created from its CLSID (see Constructor)
dim clsid as CLSID
CLSIDFromProgID( "WScript.Shell", @clsid )
dim wsh as CDispInvoke = CDispInvoke( clsid )
if wsh.IsObject() then
print wsh.Invoke( "ExpandEnvironmentStrings", "%SystemRoot%" ).ToStr()
' A property that returns an object gives another CDispInvoke
dim env as CDispInvoke = wsh.Get( "Environment", "Process" )
print "OS = "; env.Get( "Item", "OS" ).ToStr()
end if
end scope
CoUninitialize()
return 0
end function
end main()It prints:
C:\Reports\summary.txt
docx
Error &h80020006
Unknown name.
C:\Windows
OS = Windows_NT
| Member | Does |
|---|---|
| Constructor | Creates an object, or wraps one you already have. |
| Destructor | Releases the object and uninitialises COM. |
| IsObject | Tells whether there is an object. |
| DispPtr | Returns the IDispatch pointer. |
| DispObj | Returns the IDispatch pointer with a reference of its own. |
| vptr | Releases the object and returns the address of the pointer, for an output parameter. |
| Clear | Releases the object. |
| Let | Replaces the object with another. |
| Attach | Takes over an IDispatch pointer. |
| Detach | Gives up the object and returns it. |
| GetLcid, SetLcid | Read or set the locale passed with each call. |
| GetVarResult | Returns the result of the last call. |
| GetArgErr | Returns which argument a type error was about. |
| GetLastResult, SetResult | Read or set the HRESULT of the last call. |
| GetErrorInfo | Describes an HRESULT in words. |
| DispInvoke | Calls a member with an array of arguments and any flags. |
| Get | Reads a property. |
| Put | Sets a property. |
| Set | Sets a property, with indexes, and returns the result. |
| PutRef | Sets a property to an object reference. |
| SetRef | Sets a property to an object reference, with indexes. |
| Invoke | Calls a method. |
constructor
constructor( byval pdisp as IDispatch ptr, byval fAddRef as boolean = false )
constructor( byval vDisp as VARIANT, byval fAddRef as boolean = true )
constructor( byval vDisp as VARIANT ptr, byval fAddRef as boolean = true )
constructor( byref cvDisp as DVARIANT )
constructor( byref wszProgID as const wstring, byref wszLicKey as wstring = "" )
constructor( byref wszClsID as const wstring, byref wszIID as const wstring )
constructor( byref classID as const CLSID )
constructor( byref classID as const CLSID, byref riid as const IID )
constructor( byref wszLibName as const wstring, byref rclsid as const CLSID, byref riid as const IID, byref wszLicKey as wstring = "" )
constructor( byref wszLibName as const wstring, byref wszClsid as const wstring, byref wszIid as const wstring, byref wszLicKey as wstring = "" )Every form first initialises COM on the thread.
-
No argument: an empty
CDispInvoke, for Attach, Let or vptr. -
An
IDispatchpointer: wraps it. WithfAddRef=false, the default, theCDispInvoketakes over the reference you hold (the usual case for a pointer a method returned to you); withtrueit adds a reference of its own. -
A
VARIANT,VARIANT ptrorDVARIANTof typeVT_DISPATCH: wraps the object it holds, adding a reference (theVARIANTforms unlessfAddRefisfalse). The variant keeps its own reference. Any other type gives an emptyCDispInvoke. This is how an object returned by Get or Invoke becomes callable. -
A ProgID or CLSID string, such as
"Scripting.Dictionary"or a CLSID in braces ("{…}"), with an optional licence key: creates an in-process object. The pointer kept is the object'sIUnknown, not asked forIDispatch; see the introduction. -
A CLSID string and an IID string: has the same parameter types as the form above. With two
string literals the build stops with an internal compiler error; with two
wstringvariables it compiles, but did not createScripting.Dictionaryfrom its CLSID and the IID ofIDictionaryin a test. Use theCLSIDandIIDform instead. -
A
CLSID, optionally with anIID: creates an in-process object and asks it forIDispatch. If the object has none, the pointer it returned is kept anyway, and calls on it are not safe. -
A DLL path, a CLSID and an IID (as GUIDs or strings), with an optional licence key: loads
the DLL itself and creates the object from its class factory, without the registry. Ask for
IID_IDispatchor a dual interface. This suits only in-process components that are not part of Windows or of an application and do not need a container. Do not pass a licence key to these forms: with one they ask the DLL forIClassFactoryand then call it as anIClassFactory2.
| Parameter | Meaning |
|---|---|
pdisp |
An IDispatch pointer. |
vDisp, cvDisp
|
A variant holding an object. |
fAddRef |
Whether to add a reference (see above). |
wszProgID |
A ProgID, or a CLSID in braces. |
wszLicKey |
A licence key, for licensed components; usually omitted. |
wszClsID, wszIID
|
A CLSID and an IID as strings. |
classID, rclsid, riid
|
A CLSID and an IID as GUIDs. |
wszLibName |
The full path of the DLL. |
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
dim clsid as CLSID
CLSIDFromProgID( "WScript.Shell", @clsid )
dim pWsh as CDispInvoke = CDispInvoke( clsid )Microsoft Learn: CoCreateInstance
destructorClears the last result, releases the object and, when its constructor's CoInitialize
succeeded, calls CoUninitialize().
Example
scope
dim pDic as CDispInvoke = "Scripting.Dictionary"
end scope ' the dictionary is released herefunction IsObject() as booleanCheck it after creating an object: a ProgID that is not registered gives an empty
CDispInvoke, not an error.
Returns true when the CDispInvoke holds an object.
Example
dim p as CDispInvoke = "No.Such.Object"
if p.IsObject() = false then print "not registered"function DispPtr() as IDispatch ptrReturns m_pDisp, to pass to a function that wants the object. The reference stays with the
CDispInvoke: do not release it. *obj returns the same.
Returns the pointer, or NULL.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
dim pDisp as IDispatch ptr = pDic.DispPtr()function DispObj() as IDispatch ptrReturns the pointer after adding a reference, for code that keeps it. Release it when done, for
instance by handing it to a CDispInvoke constructor, which takes the reference over.
Returns the pointer, or NULL when there is no object.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
dim pSame as CDispInvoke = pDic.DispObj() ' two wrappers, one objectfunction vptr() as IDispatch ptr ptrReleases the object, as Clear does, and returns the address of m_pDisp, for a method
with an output IDispatch ptr ptr parameter: the object it writes there becomes the
CDispInvoke's.
Returns the address of m_pDisp.
Example
dim pObj as CDispInvoke
dim ppDisp as IDispatch ptr ptr = pObj.vptr()sub ClearReleases the object and clears the last result, leaving the CDispInvoke empty.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.Clear()
print pDic.IsObject() ' falseoperator let( byval pdisp as IDispatch ptr )
operator let( byval vDisp as VARIANT ptr )
operator let( byval vDisp as VARIANT )
operator let( byref cvDisp as DVARIANT )Releases the current object and wraps another, adding a reference to it: an IDispatch
pointer, or a VARIANT, VARIANT ptr or DVARIANT of type VT_DISPATCH. Anything else, or
NULL, leaves the CDispInvoke empty.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
dim pOther as CDispInvoke
pOther = pDic.DispPtr()function Attach( byval pdisp as IDispatch ptr, byval fAddRef as boolean = false ) as HRESULT
function Attach( byval vDisp as VARIANT ptr ) as HRESULTReleases the current object and takes over another.
- The pointer form takes over the reference you hold, or adds one when
fAddRefistrue. - The
VARIANT ptrform takes an object of typeVT_DISPATCHand sets the variant toVT_EMPTYwithout releasing it. It also adds a reference, so the object keeps one reference more than it should and is not freed when theCDispInvokereleases it; preferAttach( pvar->pdispVal )followed bypvar->vt = VT_EMPTY.
Returns S_OK, or E_INVALIDARG for NULL or a variant that holds no object.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
dim pDisp as IDispatch ptr = pDic.Detach()
dim pOwner as CDispInvoke
pOwner.Attach( pDisp ) ' takes over the reference Detach gavefunction Detach() as IDispatch ptr
function Detach( byval pvar as VARIANT ptr ) as HRESULTGives up the object and leaves the CDispInvoke empty. The first form returns the pointer,
whose reference is now yours to release; the second stores it in pvar as VT_DISPATCH,
clearing pvar first.
Returns the pointer; or, for the variant form, S_OK, E_POINTER when there is no object
and E_INVALIDARG for NULL.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
dim v as VARIANT
pDic.Detach( @v )
VariantClear( @v )function GetLcid() as LCID
sub SetLcid( byval _lcid as LCID )Read or set the locale identifier that Get, Put, Set,
PutRef, SetRef and Invoke pass with each call, for objects
that read numbers and dates in text by locale. It starts as LOCALE_USER_DEFAULT (&h400).
DispInvoke takes its own lcid argument instead.
Returns the locale identifier (GetLcid).
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.SetLcid( LOCALE_INVARIANT )
print hex( pDic.GetLcid() ) ' 7Ffunction GetVarResult() as DVARIANTReturns a copy of the value the last call returned: what Invoke and Get give
back, and what is left after the forms that return an HRESULT.
Returns the value; empty when the call failed or returned nothing.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.DispInvoke( DISPATCH_PROPERTYGET, "Count" )
print pDic.GetVarResult().ToStr() ' 0function GetArgErr() as UINTAfter a call that failed with DISP_E_TYPEMISMATCH or DISP_E_PARAMNOTFOUND, returns the
position of the argument at fault. Positions count in the reversed order IDispatch uses: the
last argument is 0.
Returns the position; 0 otherwise.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.Invoke( "Add", "k", "v" )
if pDic.GetLastResult() = DISP_E_TYPEMISMATCH then print "argument"; pDic.GetArgErr()function GetLastResult() as HRESULT
function SetResult( byval Result as HRESULT ) as HRESULTGetLastResult returns the HRESULT of the last call: S_OK (0) on success,
DISP_E_UNKNOWNNAME for a member that does not exist, DISP_E_EXCEPTION when the object raised
an error, E_POINTER when there is no object. SetResult stores a code, as every call does.
Returns the code (SetResult returns the code it stored).
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.Invoke( "Add", "a", 1 )
pDic.Invoke( "Add", "a", 2 ) ' the key exists already
print hex( pDic.GetLastResult() ) ' 80020009function GetErrorInfo( byval nError as long = -1 ) as ustringReturns the system's description of an HRESULT, by default the last result. For a nonzero code
the text starts with Error &h and the code in hex on a line of its own. When the object raised
an error (DISP_E_EXCEPTION) only the general "Exception occurred." is available: the object's
own message is not collected.
Returns the description.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.Invoke( "NoSuchMethod" )
print pDic.GetErrorInfo() ' Error &h80020006, Unknown name.Microsoft Learn: FormatMessageW
function DispInvoke( byval wFlags as WORD, byval dispID as .DISPID, byval prgArgs as VARIANT ptr = NULL, byval cArgs as UINT = 0, byval lcid as LCID = LOCALE_USER_DEFAULT ) as HRESULT
function DispInvoke( byval wFlags as WORD, byval pwszName as wstring ptr, byval prgArgs as VARIANT ptr = NULL, byval cArgs as UINT = 0, byval lcid as LCID = LOCALE_USER_DEFAULT ) as HRESULTThe call the other members are built on. Calls the member, given by DISPID or by name (looked
up with GetIDsOfNames first), with cArgs arguments in the array at prgArgs in reverse
order, the last argument first, and the DISPATCH_* flags in wFlags: DISPATCH_METHOD,
DISPATCH_PROPERTYGET, DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYPUTREF. For a put, the
value is the first element of the array. The result goes to GetVarResult.
Returns the HRESULT, also stored for GetLastResult: S_OK,
DISP_E_UNKNOWNNAME, DISP_E_MEMBERNOTFOUND, DISP_E_BADPARAMCOUNT, DISP_E_TYPEMISMATCH,
DISP_E_EXCEPTION …; E_POINTER when there is no object.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.Invoke( "Add", "c", 3 )
dim key as DVARIANT = "c"
dim args(0) as VARIANT
args(0) = key ' a shallow copy: key must outlive the call
pDic.DispInvoke( DISPATCH_PROPERTYGET, "Item", @args(0), 1 )Microsoft Learn: IDispatch::Invoke
function Get( byval dispID as DISPID, byval prgArgs as VARIANT ptr, byval cArgs as UINT, byval lcid as LCID = LOCALE_USER_DEFAULT ) as HRESULT
function Get( byval pwszName as wstring ptr, byval prgArgs as VARIANT ptr, byval cArgs as UINT, byval lcid as LCID = LOCALE_USER_DEFAULT ) as HRESULT
function Get( byval pwszName as wstring ptr ) as DVARIANT
function Get( byval dispID as DISPID ) as DVARIANT
function Get( byval pwszName as wstring ptr, byref dv as DVARIANT ) as DVARIANT
function Get( byval dispID as DISPID, byref dv as DVARIANT ) as DVARIANT
function Get( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT ) as DVARIANT
function Get( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT ) as DVARIANTReads a property, by name or DISPID, with up to two arguments (an indexed property such as a
collection's Item). It calls with DISPATCH_METHOD or DISPATCH_PROPERTYGET, so a method that
returns a value works too. The forms with an argument array return the HRESULT and leave the
value for GetVarResult.
Returns the value (empty on failure), or the HRESULT.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.Invoke( "Add", "a", "Apple" )
print pDic.Get( "Count" ).ToStr(), pDic.Get( "Item", "a" ).ToStr() ' 1 AppleMicrosoft Learn: IDispatch::Invoke
property Put( byval dispID as DISPID, byref dv as DVARIANT )
property Put( byval pwszName as wstring ptr, byref dv as DVARIANT )Sets a property that takes no index to dv. It is a property, so it is written as an
assignment; check GetLastResult afterwards.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.Put( "CompareMode" ) = DVARIANT( 1 ) ' text comparefunction Set( byval dispID as DISPID, byref dv as DVARIANT ) as HRESULT
function Set( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT ) as HRESULT
function Set( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT ) as HRESULT
function Set( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT ) as HRESULT
function Set( byval pwszName as wstring ptr, byref dv as DVARIANT ) as HRESULT
function Set( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT ) as HRESULT
function Set( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT ) as HRESULT
function Set( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT ) as HRESULTSets a property; with more than one argument, the last is the new value and the ones before it
are the indexes: Set( "Item", key, value ). The four-argument forms pass only three of them to
the object: the first argument is left out.
Returns the HRESULT.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
dim key as DVARIANT = "a"
dim value as DVARIANT = "Avocado"
pDic.Set( "Item", key, value ) ' adds or replaces the itemproperty PutRef( byval dispID as DISPID, byref dv as DVARIANT )
property PutRef( byval pwszName as wstring ptr, byref dv as DVARIANT )
property PutRef( byval dispID as DISPID, byval pv as any ptr )
property PutRef( byval pwszName as wstring ptr, byval pv as any ptr )Sets a property that holds an object, by reference, as a Set statement does in a script. The
any ptr forms take an interface pointer and pass it as VT_UNKNOWN, adding a reference for the
call. Check GetLastResult afterwards.
Example
dim pRs as CDispInvoke = "ADODB.Recordset"
dim pCn as CDispInvoke = "ADODB.Connection"
pRs.PutRef( "ActiveConnection" ) = DVARIANT( pCn.DispPtr(), true )
if pRs.GetLastResult() <> S_OK then print pRs.GetErrorInfo()function SetRef( byval dispID as DISPID, byref dv as DVARIANT ) as HRESULT
function SetRef( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT ) as HRESULT
function SetRef( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT ) as HRESULT
function SetRef( byval pwszName as wstring ptr, byref dv as DVARIANT ) as HRESULT
function SetRef( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT ) as HRESULT
function SetRef( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT ) as HRESULTPutRef with indexes, like Set: the last argument is the object, those before it are the indexes.
Returns the HRESULT.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
dim pInner as CDispInvoke = "Scripting.Dictionary"
dim key as DVARIANT = "child"
dim obj as DVARIANT = DVARIANT( pInner.DispPtr(), true )
pDic.SetRef( "Item", key, obj ) ' stores the dictionary itself as the itemfunction Invoke( byval dispID as DISPID ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT, byref dv13 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT, byref dv13 as DVARIANT, byref dv14 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT, byref dv13 as DVARIANT, byref dv14 as DVARIANT, byref dv15 as DVARIANT ) as DVARIANT
function Invoke( byval dispID as DISPID, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT, byref dv13 as DVARIANT, byref dv14 as DVARIANT, byref dv15 as DVARIANT, byref dv16 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT, byref dv13 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT, byref dv13 as DVARIANT, byref dv14 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT, byref dv13 as DVARIANT, byref dv14 as DVARIANT, byref dv15 as DVARIANT ) as DVARIANT
function Invoke( byval pwszName as wstring ptr, byref dv1 as DVARIANT, byref dv2 as DVARIANT, byref dv2 as DVARIANT, byref dv3 as DVARIANT, byref dv4 as DVARIANT, byref dv5 as DVARIANT, byref dv6 as DVARIANT, byref cvAg7 as DVARIANT, byref cvAg8 as DVARIANT, byref dv9 as DVARIANT, byref dv10 as DVARIANT, byref dv11 as DVARIANT, byref dv12 as DVARIANT, byref dv13 as DVARIANT, byref dv14 as DVARIANT, byref dv15 as DVARIANT, byref dv16 as DVARIANT ) as DVARIANTCalls a method, by name or DISPID, with up to 16 arguments in order. It calls with
DISPATCH_METHOD or DISPATCH_PROPERTYGET, so a property read works too. From three arguments on,
the declarations name the third parameter dv2 again (and the eighth and ninth cvAg7 and
cvAg8); the names do not matter to a caller, and the arguments still go in the order given.
Returns the value the method returned, empty for a method that returns nothing or on failure; GetLastResult tells which.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
pDic.Invoke( "Add", "a", "Apple" )
print pDic.Invoke( "Exists", "a" ).ToStr() ' -1, VARIANT_TRUEMicrosoft Learn: IDispatch::GetIDsOfNames
| Function | Does |
|---|---|
| Operator * (dispatch pointer) | Returns the IDispatch pointer. |
operator *( byref cdi as CDispInvoke ) as IDispatch ptrReturns m_pDisp, like DispPtr. The reference stays with the CDispInvoke.
Returns the pointer, or NULL.
Example
dim pDic as CDispInvoke = "Scripting.Dictionary"
if *pDic then print "created"- sys/win/com
- DVARIANT, the type of every argument and result
-
DSafeArray, for the arrays methods such as
Keysreturn -
COM procedures for
NewCom,GetComandAnyCom - Microsoft Learn: IDispatch
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing