Class

IUnknown


Description

IUnknown is the common interface supported by all COM objects.

Methods

Name

Parameters

Returns

Shared

AddRef

UInt32

Constructor

p As Ptr

Handle

Ptr

QueryInterface

riid As Ptr, ByRef out As Ptr

Integer

Release

UInt32

Method descriptions


IUnknown.AddRef

AddRef As UInt32

Increments a reference count and returns the value of the reference count.


IUnknown.Constructor

Constructor(p As Ptr)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a new IUnknown class from the supplied pointer. The constructor does not automatically add a reference count, but when the destructor is called a reference is released.


IUnknown.Handle

Handle As Ptr

Returns the raw IUnknown pointer.


IUnknown.QueryInterface

QueryInterface(riid As Ptr, ByRef out As Ptr) As Integer

Retrieves the address of a specified interface.

The following automates Internet Explorer and queries for a specific interface (each interface is identified by a unique IID)

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

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

' Query for the IID_IWebBrowser2 interface
Var iid As MemoryBlock = COM.IIDFromString("{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}")
Var out As Ptr
If 0 = unk.QueryInterface(iid, out) Then
  ' Yay this interface exists
  Break
End If

IUnknown.Release

Release As UInt32

Decrements a reference count and returns the value of the reference count.

Sample code

The following automates Internet Explorer and queries for a specific interface (each interface is identified by a unique IID)

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

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

' Query for the IID_IWebBrowser2 interface
Var iid As MemoryBlock = COM.IIDFromString("{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}")
Var out As Ptr
If 0 = unk.QueryInterface(iid, out) Then
  ' Yay this interface exists
  Break
End If

Compatibility

All project types on all supported operating systems.

See also

Object parent class; COM module; IDispatch, IEnumVARIANT, IPicture.