Module

# COM

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

## Description

Classes and functions to deal with <span class="title-ref">COM</span> components (i.e. ActiveX Controls and Automation).

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                         | Parameters                                                                                                             | Returns                                  | Shared |
|----------------------------------------------|------------------------------------------------------------------------------------------------------------------------|------------------------------------------|--------|
| `FreeVARIANT<com.freevariant>`               | oleVariant As `MemoryBlock</api/language/memoryblock>`                                                                 |                                          |        |
| `IIDFromString<com.iidfromstring>`           | iidString As `String</api/data_types/string>`                                                                          | `MemoryBlock</api/language/memoryblock>` |        |
| `RBVariantToVARIANT<com.rbvarianttovariant>` | v As `Variant</api/data_types/variant>`, addByref As `Boolean</api/data_types/boolean>` = `False</api/language/false>` | `MemoryBlock</api/language/memoryblock>` |        |
| `StringFromIID<com.stringfromiid>`           | iid As `Ptr</api/data_types/additional_types/ptr>`                                                                     | `String</api/data_types/string>`         |        |
| `VARIANTToRBVariant<com.varianttorbvariant>` | oleVar As `Ptr</api/data_types/additional_types/ptr>`                                                                  | `Variant</api/data_types/variant>`       |        |

## Method descriptions

<div id="com.freevariant">

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

</div>

<div class="rst-class">

forsearch

</div>

COM.FreeVARIANT

**FreeVARIANT**(oleVariant As `MemoryBlock</api/language/memoryblock>`)

> Frees an OLE VARIANT.
>
> ``` xojo
> ' oleVar holds an OLE VARIANT which contains a BSTR that needs to be freed
> Var oleVar As MemoryBlock = COM.RBVariantToVARIANT("test")
>
> ' ... use oleVar
>
> COM.FreeVARIANT( oleVar )
>
> ' Note: it is ok to free any type of OLE VARIANT, for example,
> '       if the OLE VARIANT contains an Integer, calling FreeVARIANT is harmless
> ```

<div id="com.iidfromstring">

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

</div>

<div class="rst-class">

forsearch

</div>

COM.IIDFromString

**IIDFromString**(iidString As `String</api/data_types/string>`) As `MemoryBlock</api/language/memoryblock>`

> Converts an IID string representation of the form {B1EFC382-9355-11D0-835C-00AA003CCABD} to an actual IID.
>
> ``` xojo
> Var iid As MemoryBlock
> iid = COM.IIDFromString( "{B1EFC382-9355-11D0-835C-00AA003CCABD}" )
> ```

<div id="com.rbvarianttovariant">

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

</div>

<div class="rst-class">

forsearch

</div>

COM.RBVariantToVARIANT

**RBVariantToVARIANT**(v As `Variant</api/data_types/variant>`, addByref As `Boolean</api/data_types/boolean>` = `False</api/language/false>`) As `MemoryBlock</api/language/memoryblock>`

> Converts an RB Variant to an OLE VARIANT. If addByref is True then the VARIANT type will include VT_BYREF.
>
> ``` xojo
> ' oleVar holds an OLE VARIANT which contains a BSTR that needs to be freed
> Var oleVar As MemoryBlock = COM.RBVariantToVARIANT("test")
>
> ' ... use oleVar
>
> COM.FreeVARIANT( oleVar )
> ```

<div id="com.stringfromiid">

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

</div>

<div class="rst-class">

forsearch

</div>

COM.StringFromIID

**StringFromIID**(iid As `Ptr</api/data_types/additional_types/ptr>`) As `String</api/data_types/string>`

> Converts an IID to a string representation of the form {B1EFC382-9355-11D0-835C-00AA003CCABD}.
>
> ``` xojo
> Var iid As MemoryBlock
> iid = COM.IIDFromString( "{21D6D48E-A88B-11D0-83DD-00AA003CCABD}" )
>
> MessageBox COM.StringFromIID( iid )
> ```

<div id="com.varianttorbvariant">

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

</div>

<div class="rst-class">

forsearch

</div>

COM.VARIANTToRBVariant

**VARIANTToRBVariant**(oleVar As `Ptr</api/data_types/additional_types/ptr>`) As `Variant</api/data_types/variant>`

> Converts an OLE VARIANT to an RB Variant.
>
> ``` xojo
> Var oleVar As MemoryBlock = COM.RBVariantToVARIANT( 2012 )
> Var v As Variant = COM.VARIANTToRBVariant( oleVar )
> ```

## Notes

Refer to the [Microsoft COM documentation](https://msdn.microsoft.com/en-us/library/windows/apps/mt592905.aspx) for full details on all classes, constants, structures, etc. used by <span class="title-ref">COM</span>.

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

### Classes

Each class is described in its own section:

| Name                                         | Super Class                                          | Description                                                                                                                                                          |
|----------------------------------------------|------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `IUnknown</api/windows/iunknown>`            |                                                      | The common interface supported by all <span class="title-ref">COM</span> objects                                                                                     |
| `IDispatch</api/windows/idispatch>`          | `IUnknown</api/windows/iunknown>`                    | The common interface exposed by Automation servers                                                                                                                   |
| `IEnumVARIANT</api/windows/ienumvariant>`    | `IUnknown</api/windows/iunknown>`                    | This interface provides a way to enumerate a collection of variants                                                                                                  |
| `IPicture</api/windows/ipicture>`            | `IUnknown</api/windows/iunknown>`                    | This interface manages a picture object and its properties. Get the details [here.](https://msdn.microsoft.com/en-us/library/windows/desktop/ms680761(v=vs.85).aspx) |
| `COMException</api/exceptions/comexception>` | `RuntimeException</api/exceptions/runtimeexception>` | Raised when a <span class="title-ref">COM</span> exception is encountered                                                                                            |

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

### Result

| Class Constant | Description                    |
|----------------|--------------------------------|
| S_OK           | Result returned without error. |
| S_FALSE        | Result returned with an error. |

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

### Invoke

These constants can be passed as flags to the IDispatch.Invoke method:

| Class Constant          | Description                                                                                                                                                  |
|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| DISPATCH_METHOD         | The member is invoked as a method. If a property has the same name, both this and the DISPATCH_PROPERTYGET flag may be set.                                  |
| DISPATCH_PROPERTYGET    | The member is retrieved as a property or data member.                                                                                                        |
| DISPATCH_PROPERTYPUT    | The member is changed as a property or data member.                                                                                                          |
| DISPATCH_PROPERTYPUTREF | The member is changed by a reference assignment, rather than a value assignment. This flag is valid only when the property accepts a reference to an object. |

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

### Size Constants

These constants represent the sizes of common <span class="title-ref">COM</span> structures:

| Class Constant | Description                                                                                                    |
|----------------|----------------------------------------------------------------------------------------------------------------|
| SIZEOF_PTR     | The size in bytes of a pointer. This value is platform-dependent: 4 on 32-bit systems and 8 on 64-bit systems. |
| SIZEOF_VARIANT | The size in bytes of an OLE VARIANT structure.                                                                 |

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

### Locale Constants

Used to specify the locale for <span class="title-ref">COM</span> calls such as `IDispatch.Invoke<idispatch.invoke>`:

| Class Constant      | Description                              |
|---------------------|------------------------------------------|
| LOCALE_USER_DEFAULT | The default locale for the current user. |

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

### Structures

Used for a variety of <span class="title-ref">COM</span> calls. Refer to [Microsoft's documentation](https://docs.microsoft.com/en-us/windows/win32/api/oaidl/) for details.

||
||

:header

## Compatibility

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

<div class="seealso">

`COMException</api/exceptions/comexception>` exception

</div>
