Class

# IUnknown

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

<span class="title-ref">IUnknown</span> is the common interface supported by all COM objects.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                      | Parameters                                                                                                                           | Returns                                           | Shared |
|-------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|--------|
| `AddRef<iunknown.addref>`                 |                                                                                                                                      | `UInt32</api/data_types/additional_types/uint32>` |        |
| `Constructor<iunknown.constructor0>`      | p As `Ptr</api/data_types/additional_types/ptr>`                                                                                     |                                                   |        |
| `Handle<iunknown.handle>`                 |                                                                                                                                      | `Ptr</api/data_types/additional_types/ptr>`       |        |
| `QueryInterface<iunknown.queryinterface>` | riid As `Ptr</api/data_types/additional_types/ptr>`, `ByRef</api/language/byref>` out As `Ptr</api/data_types/additional_types/ptr>` | `Integer</api/data_types/integer>`                |        |
| `Release<iunknown.release>`               |                                                                                                                                      | `UInt32</api/data_types/additional_types/uint32>` |        |

## Method descriptions

<div id="iunknown.addref">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

IUnknown.AddRef

**AddRef** As `UInt32</api/data_types/additional_types/uint32>`

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

<div id="iunknown.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

IUnknown.Constructor

**Constructor**(p As `Ptr</api/data_types/additional_types/ptr>`)

> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> `Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.
>
> </div>
>
> Creates a new <span class="title-ref">IUnknown</span> class from the supplied pointer. The constructor does not automatically add a reference count, but when the destructor is called a reference is released.

<div id="iunknown.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

IUnknown.Handle

**Handle** As `Ptr</api/data_types/additional_types/ptr>`

> Returns the raw <span class="title-ref">IUnknown</span> pointer.

<div id="iunknown.queryinterface">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

IUnknown.QueryInterface

**QueryInterface**(riid As `Ptr</api/data_types/additional_types/ptr>`, `ByRef</api/language/byref>` out As `Ptr</api/data_types/additional_types/ptr>`) As `Integer</api/data_types/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)
>
> ``` xojo
> 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
> ```

<div id="iunknown.release">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

IUnknown.Release

**Release** As `UInt32</api/data_types/additional_types/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)

``` xojo
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

|                       |                       |
|-----------------------|-----------------------|
| **Project Types**     | Console, Desktop, Web |
| **Operating Systems** | Windows               |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `COM</api/windows/com>` module; `IDispatch</api/windows/idispatch>`, `IEnumVARIANT</api/windows/ienumvariant>`, `IPicture</api/windows/ipicture>`.

</div>
