Declare COM interface

Syntax

interface[@|#] typename :baseinterface memberfunctions [{iid}]

 

Parts

typename - interface name.

baseinterface - interface from which this interface is inherited.

memberfunctions - list of member functions. Member functions and other parts at right of typename can be declared in multiple lines (tab-indented).

iid - GUID of interface. It is implicitly used by _create, type casting, and in some other cases.

Options:

@ - declare dispinterface (functions will be called through IDispatch::Invoke). Default: declare interface (functions will be called directly through VTBL).

# - all functions are Automation-compatible (the return value actually has HRESULT type, but it is hidden from the user; if a function returns negative HRESULT value, is generated run-time error).

 

Member function syntax: 

 

[[attributes]][membertype]membername[(arguments)]

 

attributes - one or more of the following literals:

f method (default).
p property-put function.
g property-get function.
r property-put byref function.
h

function is Automation-compatible. Optional if used a, l or option #. Cannot be used with dispinterface.

 

QM 2.2.0. If function's return type is specified, [h] is interpreted like [a]. In previous versions, if only [h] was specified, the function was interpreted as not returning a value.

a function is Automation-compatible. It has [out,retval] last argument as return value. This argument is not specified in arguments, but its dereferenced type is function's type. Optional if option # is used. Cannot be used with dispinterface.
l function is Automation-compatible. It has [lcid] argument (which is not specified in arguments). Cannot be used with dispinterface.

membertype - type of function's return value. If it is int, it also should be specified.

membername - function's name.

arguments - function's arguments. Same as with dll. Parentheses (maybe empty) must be used, unless arguments are not defined.

 

See also: declarations scope

 

Remarks

Declares a COM interface. A COM interface defines functions that can be used with a COM object. Read more.

 

Interfaces also can be declared in reference files and type libraries, which allows you to use them without declaring explicitly. Many declarations are in WINAPI and WINAPIV reference files. Usage example:

 

WINAPI.ITaskScheduler ts

 

Some Windows interfaces are declared by default, by QM or in the System\Declarations folder.

 

QM 2.3.0: Can be defined optional arguments, like with dll.

 

QM 2.3.0. Allowed comments, like with type.

 

Examples

interface IDispatch :IUnknown
	#GetTypeInfoCount(*pctinfo)
	#GetTypeInfo(iTInfo lcid ITypeInfo*pTInfo)
	#GetIDsOfNames(GUID*riid word**rgszNames cNames lcid rgDispId)
	#Invoke(dispIdMember GUID*riid lcid @wFlags DISPPARAMS*pDispParams VARIANT*pVarResult EXCEPINFO*pExcepInfo *puArgErr)
	{00020400-0000-0000-C000-000000000046}

interface IAccessible :IDispatch
	[ga]IAccessible'Parent()
	[ga]ChildCount()
	[ga]IAccessible'Child(VARIANT'varChild)
	[ga]BSTR'Name(VARIANT'varChild)
	[ga]BSTR'Value(VARIANT'varChild)
	[ga]BSTR'Description(VARIANT'varChild)
	[ga]VARIANT'Role(VARIANT'varChild)
	[ga]VARIANT'State(VARIANT'varChild)
	[ga]BSTR'Help(VARIANT'varChild)
	[ga]HelpTopic(BSTR*pszHelpFile VARIANT'varChild)
	[ga]BSTR'KeyboardShortcut(VARIANT'varChild)
	[ga]VARIANT'Focus()
	[ga]VARIANT'Selection()
	[ga]BSTR'DefaultAction(VARIANT'varChild)
	[h]Select(flagsSelect VARIANT'varChild)
	[h]Location(*pxLeft *pyTop *pcxWidth *pcyHeight VARIANT'varChild)
	[a]VARIANT'Navigate(navDir VARIANT'varStart)
	[a]VARIANT'HitTest(xLeft yTop)
	[h]DoDefaultAction(VARIANT'varChild)
	[ph]Name(VARIANT'varChild BSTR'szName)
	[ph]Value(VARIANT'varChild BSTR'szValue)
	{618736e0-3c3d-11cf-810c-00aa00389b71}

interface# ITask :IScheduledWorkItem
	SetApplicationName(@*pwszApplicationName)
	GetApplicationName(@**ppwszApplicationName)
	SetParameters(@*pwszParameters)
	GetParameters(@**ppwszParameters)
	SetWorkingDirectory(@*pwszWorkingDirectory)
	GetWorkingDirectory(@**ppwszWorkingDirectory)
	SetPriority(dwPriority)
	GetPriority(*pdwPriority)
	SetTaskFlags(dwFlags)
	GetTaskFlags(*pdwFlags)
	SetMaxRunTime(dwMaxRunTimeMS)
	GetMaxRunTime(*pdwMaxRunTimeMS)
	{148BD524-A2AB-11CE-B11F-00AA00530503}

interface@ IExample :IDispatch #Method(VARIANT'v) [g]BSTR'Property() [p]Property(BSTR'name)