CoGetApartmentType function (combaseapi.h)

Returns the current apartment type and type qualifier.

Syntax

HRESULT CoGetApartmentType(
  [out] APTTYPE          *pAptType,
  [out] APTTYPEQUALIFIER *pAptQualifier
);

Parameters

[out] pAptType

APTTYPE enumeration value that specifies the type of the current apartment.

[out] pAptQualifier

APTTYPEQUALIFIER enumeration value that specifies the type qualifier of the current apartment.

Return value

Returns S_OK if the call succeeded. Otherwise, one of the following error codes is returned.

Return code Description
E_FAIL
The call could not successfully query the current apartment type and type qualifier.
E_INVALIDARG
An invalid parameter value was supplied to the function. Specifically, one or both of the parameters were set to NULL by the caller.
CO_E_NOTINITIALIZED

CoInitialize or CoInitializeEx was not called on this thread prior to calling CoGetApartmentType.

Remarks

On Windows platforms prior to Windows 7, the following actions must be taken on a thread to query the apartment type:

In multithreaded scenarios, there is a race condition which can potentially cause an Access Violation within the process when executing the above sequence of operations. The CoGetApartmentType function is recommended as it does not potentially incur the Access Violation.

Requirements

Requirement Value
Minimum supported client Windows 7 [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2 [desktop apps | UWP apps]
Target Platform Windows
Header combaseapi.h (include Objbase.h)
Library Ole32.lib
DLL Ole32.dll

See also

APTTYPE

APTTYPEQUALIFIER