diff --git a/dlls/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0.spec b/dlls/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0.spec index f8026db2353..f645c9d1d05 100644 --- a/dlls/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0.spec +++ b/dlls/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0.spec @@ -17,7 +17,7 @@ @ stub CoEnableCallCancellation @ stdcall CoFreeUnusedLibraries() ole32.CoFreeUnusedLibraries @ stdcall CoFreeUnusedLibrariesEx(long long) ole32.CoFreeUnusedLibrariesEx -@ stub CoGetApartmentType +@ stdcall CoGetApartmentType(ptr ptr) ole32.CoGetApartmentType @ stdcall CoGetCallContext(ptr ptr) ole32.CoGetCallContext @ stdcall CoGetCallerTID(ptr) ole32.CoGetCallerTID @ stub CoGetCancelObject diff --git a/dlls/api-ms-win-core-com-l1-1-1/api-ms-win-core-com-l1-1-1.spec b/dlls/api-ms-win-core-com-l1-1-1/api-ms-win-core-com-l1-1-1.spec index 56aaf367e29..d2914f0c8b8 100644 --- a/dlls/api-ms-win-core-com-l1-1-1/api-ms-win-core-com-l1-1-1.spec +++ b/dlls/api-ms-win-core-com-l1-1-1/api-ms-win-core-com-l1-1-1.spec @@ -17,7 +17,7 @@ @ stub CoEnableCallCancellation @ stdcall CoFreeUnusedLibraries() ole32.CoFreeUnusedLibraries @ stdcall CoFreeUnusedLibrariesEx(long long) ole32.CoFreeUnusedLibrariesEx -@ stub CoGetApartmentType +@ stdcall CoGetApartmentType(ptr ptr) ole32.CoGetApartmentType @ stdcall CoGetCallContext(ptr ptr) ole32.CoGetCallContext @ stdcall CoGetCallerTID(ptr) ole32.CoGetCallerTID @ stub CoGetCancelObject diff --git a/dlls/api-ms-win-downlevel-ole32-l1-1-0/api-ms-win-downlevel-ole32-l1-1-0.spec b/dlls/api-ms-win-downlevel-ole32-l1-1-0/api-ms-win-downlevel-ole32-l1-1-0.spec index a0eabe972b5..82ff0f1792f 100644 --- a/dlls/api-ms-win-downlevel-ole32-l1-1-0/api-ms-win-downlevel-ole32-l1-1-0.spec +++ b/dlls/api-ms-win-downlevel-ole32-l1-1-0/api-ms-win-downlevel-ole32-l1-1-0.spec @@ -8,7 +8,7 @@ @ stdcall CoDisconnectObject(ptr long) ole32.CoDisconnectObject @ stdcall CoFreeUnusedLibraries() ole32.CoFreeUnusedLibraries @ stdcall CoFreeUnusedLibrariesEx(long long) ole32.CoFreeUnusedLibrariesEx -@ stub CoGetApartmentType +@ stdcall CoGetApartmentType(ptr ptr) ole32.CoGetApartmentType @ stdcall CoGetClassObject(ptr long ptr ptr ptr) ole32.CoGetClassObject @ stdcall CoGetCurrentLogicalThreadId(ptr) ole32.CoGetCurrentLogicalThreadId @ stdcall CoGetInterfaceAndReleaseStream(ptr ptr ptr) ole32.CoGetInterfaceAndReleaseStream diff --git a/dlls/combase/combase.spec b/dlls/combase/combase.spec index 4bda4708e51..b612bef9c57 100644 --- a/dlls/combase/combase.spec +++ b/dlls/combase/combase.spec @@ -90,7 +90,7 @@ @ stdcall CoFreeUnusedLibrariesEx(long long) ole32.CoFreeUnusedLibrariesEx @ stdcall CoGetActivationState(int128 long ptr) ole32.CoGetActivationState @ stub CoGetApartmentID -@ stub CoGetApartmentType +@ stdcall CoGetApartmentType(ptr ptr) ole32.CoGetApartmentType @ stdcall CoGetCallContext(ptr ptr) ole32.CoGetCallContext @ stdcall CoGetCallState(long ptr) ole32.CoGetCallState @ stdcall CoGetCallerTID(ptr) ole32.CoGetCallerTID diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index 080940ec91c..de7438c78c9 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -5028,6 +5028,35 @@ HRESULT Handler_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) return CLASS_E_CLASSNOTAVAILABLE; } +/*********************************************************************** + * CoGetApartmentType [OLE32.@] + */ +HRESULT WINAPI CoGetApartmentType(APTTYPE *type, APTTYPEQUALIFIER *qualifier) +{ + struct oletls *info = COM_CurrentInfo(); + + FIXME("(%p, %p): semi-stub\n", type, qualifier); + + if (!type || !qualifier) + return E_INVALIDARG; + + if (!info) + return E_OUTOFMEMORY; + + if (!info->apt) + *type = APTTYPE_CURRENT; + else if (info->apt->multi_threaded) + *type = APTTYPE_MTA; + else if (info->apt->main) + *type = APTTYPE_MAINSTA; + else + *type = APTTYPE_STA; + + *qualifier = APTTYPEQUALIFIER_NONE; + + return info->apt ? S_OK : CO_E_NOTINITIALIZED; +} + /*********************************************************************** * DllMain (OLE32.@) */ diff --git a/dlls/ole32/ole32.spec b/dlls/ole32/ole32.spec index 04c9f1e3ccd..c8361768779 100644 --- a/dlls/ole32/ole32.spec +++ b/dlls/ole32/ole32.spec @@ -23,6 +23,7 @@ @ stdcall CoFreeUnusedLibraries() @ stdcall CoFreeUnusedLibrariesEx(long long) @ stdcall CoGetActivationState(int128 long ptr) +@ stdcall CoGetApartmentType(ptr ptr) @ stdcall CoGetCallContext(ptr ptr) @ stdcall CoGetCallState(long ptr) @ stdcall CoGetCallerTID(ptr) diff --git a/dlls/ole32/tests/compobj.c b/dlls/ole32/tests/compobj.c index 6fa6dfc4a05..de511ab3960 100644 --- a/dlls/ole32/tests/compobj.c +++ b/dlls/ole32/tests/compobj.c @@ -70,6 +70,7 @@ static HRESULT (WINAPI * pCoSwitchCallContext)(IUnknown *pObject, IUnknown **ppO static HRESULT (WINAPI * pCoGetTreatAsClass)(REFCLSID clsidOld, LPCLSID pClsidNew); static HRESULT (WINAPI * pCoTreatAsClass)(REFCLSID clsidOld, REFCLSID pClsidNew); static HRESULT (WINAPI * pCoGetContextToken)(ULONG_PTR *token); +static HRESULT (WINAPI * pCoGetApartmentType)(APTTYPE *type, APTTYPEQUALIFIER *qualifier); static LONG (WINAPI * pRegDeleteKeyExA)(HKEY, LPCSTR, REGSAM, DWORD); static LONG (WINAPI * pRegOverridePredefKey)(HKEY key, HKEY override); @@ -2879,6 +2880,59 @@ if (0) /* crashes on native */ IMalloc_Release(imalloc); } +static void test_CoGetApartmentType(void) +{ + APTTYPEQUALIFIER qualifier; + APTTYPE type; + HRESULT hr; + + if (!pCoGetApartmentType) + { + win_skip("CoGetApartmentType not present\n"); + return; + } + + hr = pCoGetApartmentType(NULL, NULL); + ok(hr == E_INVALIDARG, "CoGetApartmentType succeeded, error: 0x%08x\n", hr); + + type = 0xdeadbeef; + hr = pCoGetApartmentType(&type, NULL); + ok(hr == E_INVALIDARG, "CoGetApartmentType succeeded, error: 0x%08x\n", hr); + ok(type == 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", type); + + qualifier = 0xdeadbeef; + hr = pCoGetApartmentType(NULL, &qualifier); + ok(hr == E_INVALIDARG, "CoGetApartmentType succeeded, error: 0x%08x\n", hr); + ok(qualifier == 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", qualifier); + + type = 0xdeadbeef; + qualifier = 0xdeadbeef; + hr = pCoGetApartmentType(&type, &qualifier); + ok(hr == CO_E_NOTINITIALIZED, "CoGetApartmentType succeeded, error: 0x%08x\n", hr); + ok(type == APTTYPE_CURRENT, "Expected APTTYPE_CURRENT, got %u\n", type); + ok(qualifier == APTTYPEQUALIFIER_NONE, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier); + + type = 0xdeadbeef; + qualifier = 0xdeadbeef; + hr = pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + ok(hr == S_OK, "CoInitializeEx failed, error: 0x%08x\n", hr); + hr = pCoGetApartmentType(&type, &qualifier); + ok(hr == S_OK, "CoGetApartmentType failed, error: 0x%08x\n", hr); + ok(type == APTTYPE_MAINSTA, "Expected APTTYPE_MAINSTA, got %u\n", type); + ok(qualifier == APTTYPEQUALIFIER_NONE, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier); + CoUninitialize(); + + type = 0xdeadbeef; + qualifier = 0xdeadbeef; + hr = pCoInitializeEx(NULL, COINIT_MULTITHREADED); + ok(hr == S_OK, "CoInitializeEx failed, error: 0x%08x\n", hr); + hr = pCoGetApartmentType(&type, &qualifier); + ok(hr == S_OK, "CoGetApartmentType failed, error: 0x%08x\n", hr); + ok(type == APTTYPE_MTA, "Expected APTTYPE_MTA, got %u\n", type); + ok(qualifier == APTTYPEQUALIFIER_NONE, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier); + CoUninitialize(); +} + static void init_funcs(void) { HMODULE hOle32 = GetModuleHandleA("ole32"); @@ -2890,6 +2944,7 @@ static void init_funcs(void) pCoGetTreatAsClass = (void*)GetProcAddress(hOle32,"CoGetTreatAsClass"); pCoTreatAsClass = (void*)GetProcAddress(hOle32,"CoTreatAsClass"); pCoGetContextToken = (void*)GetProcAddress(hOle32, "CoGetContextToken"); + pCoGetApartmentType = (void*)GetProcAddress(hOle32, "CoGetApartmentType"); pRegDeleteKeyExA = (void*)GetProcAddress(hAdvapi32, "RegDeleteKeyExA"); pRegOverridePredefKey = (void*)GetProcAddress(hAdvapi32, "RegOverridePredefKey"); pCoInitializeEx = (void*)GetProcAddress(hOle32, "CoInitializeEx"); @@ -2944,4 +2999,5 @@ START_TEST(compobj) test_CoWaitForMultipleHandles(); test_CoGetMalloc(); test_OleRegGetUserType(); + test_CoGetApartmentType(); } diff --git a/include/objbase.h b/include/objbase.h index d73f220f02f..02656d18ff0 100644 --- a/include/objbase.h +++ b/include/objbase.h @@ -285,6 +285,7 @@ HRESULT WINAPI CoInitialize(LPVOID lpReserved); HRESULT WINAPI CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit); void WINAPI CoUninitialize(void); DWORD WINAPI CoGetCurrentProcess(void); +HRESULT WINAPI CoGetApartmentType(APTTYPE *type, APTTYPEQUALIFIER *qualifier); HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree); void WINAPI CoFreeAllLibraries(void); diff --git a/include/objidl.idl b/include/objidl.idl index 335282d74de..168e533c472 100644 --- a/include/objidl.idl +++ b/include/objidl.idl @@ -2327,6 +2327,15 @@ typedef enum _APTTYPE { APTTYPE_MAINSTA = 3 } APTTYPE; +typedef enum _APTTYPEQUALIFIER { + APTTYPEQUALIFIER_NONE, + APTTYPEQUALIFIER_IMPLICIT_MTA, + APTTYPEQUALIFIER_NA_ON_MTA, + APTTYPEQUALIFIER_NA_ON_STA, + APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA, + APTTYPEQUALIFIER_NA_ON_MAINSTA +} APTTYPEQUALIFIER; + typedef enum _THDTYPE { THDTYPE_BLOCKMESSAGES = 0, THDTYPE_PROCESSMESSAGES = 1