mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-25 02:10:53 +00:00
Changed: Only call CoUninitialize if CoInitialize(Ex) succeeded
This commit is contained in:
parent
cfaceffe9e
commit
97634f2157
2 changed files with 38 additions and 5 deletions
|
@ -76,12 +76,21 @@ namespace NLMISC {
|
||||||
|
|
||||||
nlWindow CSystemUtils::s_window = EmptyWindow;
|
nlWindow CSystemUtils::s_window = EmptyWindow;
|
||||||
|
|
||||||
|
#ifdef NL_OS_WINDOWS
|
||||||
|
static bool s_mustUninit = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool CSystemUtils::init()
|
bool CSystemUtils::init()
|
||||||
{
|
{
|
||||||
#ifdef NL_OS_WINDOWS
|
#ifdef NL_OS_WINDOWS
|
||||||
// initialize COM
|
// initialize COM
|
||||||
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
if (!s_mustUninit)
|
||||||
if (FAILED(hr)) return false;
|
{
|
||||||
|
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||||
|
if (FAILED(hr)) return false;
|
||||||
|
|
||||||
|
s_mustUninit = true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -91,7 +100,12 @@ bool CSystemUtils::uninit()
|
||||||
{
|
{
|
||||||
#ifdef NL_OS_WINDOWS
|
#ifdef NL_OS_WINDOWS
|
||||||
// uninitialize COM
|
// uninitialize COM
|
||||||
CoUninitialize();
|
if (s_mustUninit)
|
||||||
|
{
|
||||||
|
CoUninitialize();
|
||||||
|
|
||||||
|
s_mustUninit = false;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -80,6 +80,26 @@ bool copyInstallerFiles(const QStringList &files, const QString &destination)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
class CCOMHelper
|
||||||
|
{
|
||||||
|
bool m_mustUninit;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CCOMHelper()
|
||||||
|
{
|
||||||
|
// to fix the bug with QFileDialog::getExistingDirectory hanging under Windows
|
||||||
|
m_mustUninit = SUCCEEDED(CoInitialize(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
~CCOMHelper()
|
||||||
|
{
|
||||||
|
// only call CoUninitialize if CoInitialize succeeded
|
||||||
|
if (m_mustUninit) CoUninitialize();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||||
|
@ -87,8 +107,7 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
// to fix the bug with QFileDialog::getExistingDirectory hanging under Windows
|
CCOMHelper comHelper;
|
||||||
CoInitialize(NULL);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NLMISC::CApplicationContext appContext;
|
NLMISC::CApplicationContext appContext;
|
||||||
|
|
Loading…
Reference in a new issue