IDispatch

From Xojo Documentation
Jump to: navigation, search

Interface


IDispatch is the common interface exposed by automation servers (like Internet Explorer, Word, Excel, etc.). For automation servers that support dual interfaces you can use the OLEObject class to automate them.

Method Description
GetIDofName Gets a single DISPID (which can be used on calls to Invoke) from the name
GetTypeInfo Retrieves the type information for an object, which can then be used to get the type information for an interface.
GetTypeInfoCount Retrieves the number of type information interfaces that an object provides (either 0 or 1).
Invoke Provides access to properties and methods exposed by an object.


Methods
GetIDofName Invoke


Examples

The following automates Internet Explorer, queries for a specific interface (each interface is identified by a unique IID), and invokes a method on the interface

Dim ie As New OLEObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate("google.com")

Dim unk As New COM.IUnknown(ie.Handle)

// Query for the IID_IWebBrowser2 interface
Dim iid As MemoryBlock = COM.IIDFromString("{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}")
Dim out As Ptr
If COM.S_OK = unk.QueryInterface(iid, out) Then
Dim disp As New COM.IDispatch(out)
Dim id As Integer = disp.GetIDofName("FullName")

// If id = -1 Then the method doesn't exist

// This method has no parameters but we still have to pass in an empty structure
Dim params As COM.DISPPARAMS

// This method returns a BSTR which is stored in an OLE VARIANT
Dim result As New MemoryBlock(COM.SIZEOF_VARIANT)

Dim err As UInt32
Dim resultCode As Integer
resultCode = disp.Invoke(id, COM.IID_NULL, COM.LOCALE_USER_DEFAULT, _
COM.DISPATCH_METHOD + COM.DISPATCH_PROPERTYGET, params, result, Nil, err)

If resultCode = COM.S_OK Then
Dim retVal As Variant = COM.VARIANTToRBVariant(result)
Msgbox "Path to IE: " + retVal

// Remember to free the OLE VARIANT
COM.FreeVARIANT(result)
End If
End If

See Also

COM module; IUnknown, IEnumVARIANT, IPicture.

Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About