1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ole2uno.hxx"
22 #include <comphelper/windowserrorstring.hxx>
23 #include <osl/thread.hxx>
24 #include <sal/log.hxx>
28 void o2u_attachCurrentThread()
30 static osl::ThreadData oleThreadData
;
32 if (!bool(reinterpret_cast<sal_IntPtr
>(oleThreadData
.getData())))
34 HRESULT hr
= CoInitializeEx(nullptr, COINIT_MULTITHREADED
);
36 { // FIXME: is it a problem that this ends up in STA currently?
37 assert(RPC_E_CHANGED_MODE
== hr
);
38 // Let's find out explicitly what apartment mode we are in.
39 SAL_WARN("extensions.olebridge", "CoInitializeEx failed"
40 << (hr
== RPC_E_CHANGED_MODE
? " (expectedly)" : "")
41 << ": " << WindowsErrorStringFromHRESULT(hr
));
43 APTTYPEQUALIFIER nAptTypeQualifier
;
44 if (SUCCEEDED(CoGetApartmentType(&nAptType
, &nAptTypeQualifier
)))
46 SAL_WARN("extensions.olebridge",
48 << (nAptType
== APTTYPE_STA
? OUString("single-threaded") :
49 (nAptType
== APTTYPE_MTA
? OUString("multi-threaded") :
50 (nAptType
== APTTYPE_NA
? OUString("neutral") :
51 (nAptType
== APTTYPE_MAINSTA
? OUString("main single-threaded") :
52 ("unknown (") + OUString::number(nAptType
) + ")"))))
54 << (nAptTypeQualifier
== APTTYPEQUALIFIER_NONE
? OUString() :
55 (nAptTypeQualifier
== APTTYPEQUALIFIER_IMPLICIT_MTA
? OUString(" (implicit)") :
56 (nAptTypeQualifier
== APTTYPEQUALIFIER_NA_ON_MTA
? OUString(" (on MTA)") :
57 (nAptTypeQualifier
== APTTYPEQUALIFIER_NA_ON_STA
? OUString(" (on STA)") :
58 (nAptTypeQualifier
== APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA
? OUString(" (on implicit MTA)") :
59 (nAptTypeQualifier
== APTTYPEQUALIFIER_NA_ON_MAINSTA
? OUString(" (on main STA)") :
60 (" (with unknown qualifier (" + OUString::number(nAptTypeQualifier
) + "))")))))))
64 oleThreadData
.setData(reinterpret_cast<void*>(true));
68 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */