|
FreeRDP
|
#include <string.h>#include <winpr/platform.h>#include <winpr/winpr.h>#include <winpr/wtypes.h>#include <winpr/error.h>
Go to the source code of this file.
Data Structures | |
| struct | wIUnknownVtbl |
| the vtable of IUnknown, the first entries of every COM vtable More... | |
| struct | wIUnknown |
| IUnknown, C form. More... | |
| struct | wComBase |
Macros | |
| #define | WINPR_COM_CALL |
| the calling convention of COM methods (STDMETHODCALLTYPE) | |
| #define | WINPR_COM_CAST(t, val) |
| defined when interfaces are declared in C++ form: C++ without WINPR_COM_CINTERFACE | |
| #define | WINPR_COM_CXX_INTERFACE(name) |
| ends the declaration of a C++ interface name: only an implementation creates it and Release() frees it (protected constructor and destructor), it is not copied. The destructor is not virtual, which would add vtable entries. | |
| #define | WINPR_COM_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) |
| defines a GUID constant visible in the including file only (nothing to link) | |
| #define | WINPR_COM_GUID_FMT |
| printf a GUID as {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}: WLog_DBG(TAG, "id=" WINPR_COM_GUID_FMT, WINPR_COM_GUID_ARGS(guid)) | |
| #define | WINPR_COM_GUID_ARGS(g) |
| #define | WINPR_COM_IUNKNOWN_VTBL(obj) |
| IUnknown calls on any interface: in C form through its vtable, in C++ form directly. In C form, WINPR_COM_IUNKNOWN_VTBL(obj) is the wIUnknownVtbl of obj (wIUnknown itself or an interface whose vtable starts with iunknown). | |
| #define | WINPR_COM_QUERY_INTERFACE(obj, iid, ppv) |
| #define | WINPR_COM_ADDREF(obj) |
| #define | WINPR_COM_RELEASE(obj) |
| #define | WINPR_COM_REFCOUNT_THUNKS(prefix) |
| prefix_AddRef and prefix_Release, for an object starting with a wComBase | |
| #define | WINPR_COM_IUNKNOWN_THUNKS(prefix, iid) |
| WINPR_COM_REFCOUNT_THUNKS plus prefix_QueryInterface answering IUnknown and iid (a const IID*, nullptr for IUnknown only). | |
| #define | WINPR_COM_IUNKNOWN_ENTRIES(prefix) |
| the initializer of a wIUnknownVtbl from prefix_QueryInterface (the thunk above or the object's own), prefix_AddRef and prefix_Release | |
Typedefs | |
| typedef void(* | pfnwComBaseFree) (wComBase *object) |
| called when the last reference goes away: releases what the object holds and frees it | |
Functions | |
| WINPR_COM_DEFINE_GUID (WINPR_IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46) | |
| IID_IUnknown, {00000000-0000-0000-C000-000000000046}. | |
| static BOOL | winpr_com_guid_equal (const GUID *a, const GUID *b) |
| IsEqualGUID. | |
| WINPR_API void | winpr_com_base_init (wComBase *object, const char *className, const wIUnknownVtbl *vtbl, pfnwComBaseFree Free) |
| sets the vtable and the reference count to 1, the caller owns that first reference. | |
| WINPR_API ULONG | winpr_com_base_add_ref (wComBase *object) |
| AddRef of an object starting with a wComBase. | |
| WINPR_API ULONG | winpr_com_base_release (wComBase *object) |
| Release of an object starting with a wComBase: calls its Free at 0. | |
| WINPR_API HRESULT | winpr_com_base_query (wComBase *object, const IID *iid, const IID *riid, void **ppv) |
| QueryInterface of an object whose only interface is iid (nullptr: IUnknown only). On success *ppv is the object, with a new reference. | |
WinPR: Windows Portable Runtime Minimal COM object support
Copyright 2026 David Fort conta.nosp@m.ct@h.nosp@m.arden.nosp@m.ing-.nosp@m.consu.nosp@m.ltin.nosp@m.g.com
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Just enough COM to implement and use objects that are binary compatible with Windows COM objects, on all platforms.
The SDK COM headers (unknwn.h, objbase.h) are never included (codespell:ignore unknwn), even on Windows: everything here has its own name (wIUnknown, WINPR_IID_IUnknown, ...), so it coexists with them in a file that includes them. The binary layout and calling convention are the Windows ones: a wIUnknown* can be passed where Windows expects an IUnknown*, and the other way around.
In C, an interface is a struct whose only member is lpVtbl, and its vtable starts with a wIUnknownVtbl named iunknown, followed by the interface's own methods:
typedef struct IFoo IFoo; typedef struct { wIUnknownVtbl iunknown; UINT32(WINPR_COM_CALL* Foo)(IFoo* This); } IFooVtbl; struct IFoo { const IFooVtbl* lpVtbl; };
This is the layout of a MIDL vtable (the three IUnknown entries, then the others), and &vtbl->iunknown is a wIUnknownVtbl without any cast. The IUnknown entries take a wIUnknown*.
In C++, as in MIDL generated headers, interfaces are classes with pure virtual methods that derive from the C++ form of wIUnknown, which gives the same layout (define WINPR_COM_CINTERFACE to get the C form in C++ too):
struct IFoo : public wIUnknown { virtual UINT32 WINPR_COM_CALL Foo() = 0; WINPR_COM_CXX_INTERFACE(IFoo) };
Such C++ interfaces must not have a virtual destructor nor overloaded methods, and only use single inheritance, or the vtable layout differs between compilers.
The WINPR_COM_QUERY_INTERFACE / ADDREF / RELEASE macros work on any interface in either form.
IIDs are passed as const IID* (winpr's POSIX REFIID is not const; on Windows it is the same pointer).
Definition in file com.h.
| struct wIUnknown |
| struct s_wComBase |

| Data Fields | ||
|---|---|---|
| const char * | className | |
| pfnwComBaseFree | Free | |
| const wIUnknownVtbl * | lpVtbl | |
| volatile LONG | refCount | |
| #define WINPR_COM_ADDREF | ( | obj | ) |
Definition at line 194 of file com.h.
| #define WINPR_COM_CALL |
| #define WINPR_COM_CAST | ( | t, | |
| val ) |
| #define WINPR_COM_CXX_INTERFACE | ( | name | ) |
ends the declaration of a C++ interface name: only an implementation creates it and Release() frees it (protected constructor and destructor), it is not copied. The destructor is not virtual, which would add vtable entries.
Definition at line 101 of file com.h.
| #define WINPR_COM_DEFINE_GUID | ( | name, | |
| l, | |||
| w1, | |||
| w2, | |||
| b1, | |||
| b2, | |||
| b3, | |||
| b4, | |||
| b5, | |||
| b6, | |||
| b7, | |||
| b8 ) |
defines a GUID constant visible in the including file only (nothing to link)
Definition at line 158 of file com.h.
| #define WINPR_COM_GUID_ARGS | ( | g | ) |
Definition at line 176 of file com.h.
| #define WINPR_COM_GUID_FMT |
printf a GUID as {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}: WLog_DBG(TAG, "id=" WINPR_COM_GUID_FMT, WINPR_COM_GUID_ARGS(guid))
Definition at line 173 of file com.h.
Referenced by winpr_com_base_query().
| #define WINPR_COM_IUNKNOWN_ENTRIES | ( | prefix | ) |
the initializer of a wIUnknownVtbl from prefix_QueryInterface (the thunk above or the object's own), prefix_AddRef and prefix_Release
Definition at line 286 of file com.h.
| #define WINPR_COM_IUNKNOWN_THUNKS | ( | prefix, | |
| iid ) |
WINPR_COM_REFCOUNT_THUNKS plus prefix_QueryInterface answering IUnknown and iid (a const IID*, nullptr for IUnknown only).
Definition at line 276 of file com.h.
| #define WINPR_COM_IUNKNOWN_VTBL | ( | obj | ) |
IUnknown calls on any interface: in C form through its vtable, in C++ form directly. In C form, WINPR_COM_IUNKNOWN_VTBL(obj) is the wIUnknownVtbl of obj (wIUnknown itself or an interface whose vtable starts with iunknown).
| #define WINPR_COM_QUERY_INTERFACE | ( | obj, | |
| iid, | |||
| ppv ) |
Definition at line 191 of file com.h.
| #define WINPR_COM_REFCOUNT_THUNKS | ( | prefix | ) |
prefix_AddRef and prefix_Release, for an object starting with a wComBase
Definition at line 264 of file com.h.
| #define WINPR_COM_RELEASE | ( | obj | ) |
| typedef void(* pfnwComBaseFree) (wComBase *object) |
| WINPR_API ULONG winpr_com_base_add_ref | ( | wComBase * | object | ) |
AddRef of an object starting with a wComBase.
Definition at line 43 of file com.c.
References winpr_com_base_add_ref().
Referenced by winpr_com_base_add_ref(), and winpr_com_base_query().


| WINPR_API void winpr_com_base_init | ( | wComBase * | object, |
| const char * | className, | ||
| const wIUnknownVtbl * | vtbl, | ||
| pfnwComBaseFree | Free ) |
sets the vtable and the reference count to 1, the caller owns that first reference.
| vtbl | the iunknown member of the vtable of the object's first interface |
Definition at line 30 of file com.c.
References winpr_com_base_init().
Referenced by freerdp_client_window_info_service_new(), plugin_services_new(), and winpr_com_base_init().


| WINPR_API HRESULT winpr_com_base_query | ( | wComBase * | object, |
| const IID * | iid, | ||
| const IID * | riid, | ||
| void ** | ppv ) |
QueryInterface of an object whose only interface is iid (nullptr: IUnknown only). On success *ppv is the object, with a new reference.
Definition at line 63 of file com.c.
References winpr_com_base_add_ref(), winpr_com_base_query(), winpr_com_guid_equal(), and WINPR_COM_GUID_FMT.
Referenced by winpr_com_base_query().


| WINPR_API ULONG winpr_com_base_release | ( | wComBase * | object | ) |
Release of an object starting with a wComBase: calls its Free at 0.
Definition at line 51 of file com.c.
References winpr_com_base_release().
Referenced by shared_subscribe(), shared_unsubscribe(), and winpr_com_base_release().


|
inlinestatic |
IsEqualGUID.
Definition at line 166 of file com.h.
Referenced by winpr_com_base_query().
