CoGetApartmentType function (combaseapi.h)
Returns the current apartment type and type qualifier.
HRESULT CoGetApartmentType( [out] APTTYPE *pAptType, [out] APTTYPEQUALIFIER *pAptQualifier );
APTTYPE enumeration value that specifies the type of the current apartment.
APTTYPEQUALIFIER enumeration value that specifies the type qualifier of the current apartment.
Returns S_OK if the call succeeded. Otherwise, one of the following error codes is returned.
||The call could not successfully query the current apartment type and type qualifier.|
||An invalid parameter value was supplied to the function. Specifically, one or both of the parameters were set to NULL by the caller.|
CoInitialize or CoInitializeEx was not called on this thread prior to calling CoGetApartmentType.
On Windows platforms prior to Windows 7, the following actions must be taken on a thread to query the apartment type:
- Call CoGetContextToken to obtain the current context token.
- Cast the context token to an IUnknown* pointer.
- Call the QueryInterface method on that pointer to obtain the IComThreadingInfo interface.
- Call the GetCurrentApartmentType method of the IComThreadingInfo interface to obtain the current 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.
|Minimum supported client||Windows 7 [desktop apps | UWP apps]|
|Minimum supported server||Windows Server 2008 R2 [desktop apps | UWP apps]|
|Header||combaseapi.h (include Objbase.h)|