-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from oblivioncth/mingw_compat
Improve compatibility with MinGW
- Loading branch information
Showing
10 changed files
with
198 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,26 @@ | ||
#define WIN32_LEAN_AND_MEAN | ||
#define NOMINMAX | ||
// ifdefs are to avoid macro redefinition warnings | ||
#ifndef WIN32_LEAN_AND_MEAN | ||
#define WIN32_LEAN_AND_MEAN | ||
#endif | ||
#ifndef NOATOM | ||
#define NOATOM | ||
#endif | ||
#ifndef NOGDI | ||
#define NOGDI | ||
#endif | ||
#ifndef NOMINMAX | ||
#define NOMINMAX | ||
#endif | ||
#ifndef NOSOUND | ||
#define NOSOUND | ||
#endif | ||
#ifndef NOHELP | ||
#define NOHELP | ||
#endif | ||
#ifndef NOMCX | ||
#define NOMCX | ||
#endif | ||
|
||
#include "windows.h" | ||
#include "ShObjIdl_core.h" | ||
|
||
// See windows.h for more "NOXXX" options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Unit Includes | ||
#include "qx-common-windows_p.h" | ||
|
||
// Qt Includes | ||
#include <QCoreApplication> | ||
#include <QThread> | ||
|
||
// Windows Includes | ||
#include "combaseapi.h" | ||
|
||
namespace Qx | ||
{ | ||
/*! @cond */ | ||
//=============================================================================================================== | ||
// ScopedCom | ||
//=============================================================================================================== | ||
|
||
//-Constructor-------------------------------------------------------------------------------------------------- | ||
//Public: | ||
ScopedCom::ScopedCom() : | ||
mThreadId(GetCurrentThreadId()), | ||
mCleanup(false) | ||
{ | ||
// Check if COM is initialized (parameter return values are ignored) | ||
APTTYPE aptType; | ||
APTTYPEQUALIFIER aptTypeQualifier; | ||
HRESULT hRes = CoGetApartmentType(&aptType, &aptTypeQualifier); | ||
if(SUCCEEDED(hRes)) | ||
return; // COM is ready, do nothing | ||
else if(hRes != CO_E_NOTINITIALIZED) | ||
{ | ||
// True error | ||
mError = SystemError::fromHresult(hRes); | ||
return; | ||
} | ||
|
||
// Init COM (shouldn't ever be needed in the main thread, but we check just in-case) | ||
auto app = QCoreApplication::instance(); | ||
bool inMainThread = app && app->thread() == QThread::currentThread(); // TODO: Use Qt 6.8 isMainThread() | ||
int tm = (inMainThread ? COINIT_APARTMENTTHREADED : COINIT_MULTITHREADED) | COINIT_DISABLE_OLE1DDE; | ||
hRes = CoInitializeEx(NULL, tm); | ||
if(!SUCCEEDED(hRes)) // Should never fail, but hey... | ||
{ | ||
mError = SystemError::fromHresult(hRes); | ||
return; | ||
} | ||
|
||
mCleanup = true; | ||
} | ||
|
||
//-Destructor-------------------------------------------------------------------------------------------------- | ||
//Public: | ||
ScopedCom::~ScopedCom() | ||
{ | ||
Q_ASSERT(mThreadId == GetCurrentThreadId()); | ||
if(mCleanup) | ||
CoUninitialize(); | ||
} | ||
|
||
//-Instance Functions-------------------------------------------------------------------------------------------- | ||
//Public: | ||
bool ScopedCom::hasError() const { return mError.isValid(); } | ||
SystemError ScopedCom::error() const { return mError; } | ||
|
||
//-Operators-------------------------------------------------------------------------------------------- | ||
//Public: | ||
ScopedCom::operator bool() const { return !hasError(); } | ||
|
||
/*! @endcond */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef QX_WINDOWS_COMMON_P_H | ||
#define QX_WINDOWS_COMMON_P_H | ||
|
||
// Qt Includes | ||
#include <QtClassHelperMacros> | ||
|
||
// Inter-component Includes | ||
#include "qx/windows/qx-windefs.h" | ||
|
||
// Extra-component Includes | ||
#include "qx/core/qx-systemerror.h" | ||
|
||
namespace Qx | ||
{ | ||
/*! @cond */ | ||
|
||
// Makes sure COM is initialized, and cleans up on deletion. | ||
// Based on QComHelper, but slightly more flexible in that it just cares COM is initialized one way or another. | ||
class ScopedCom | ||
{ | ||
Q_DISABLE_COPY_MOVE(ScopedCom); | ||
private: | ||
SystemError mError; | ||
DWORD mThreadId; // For safety check | ||
bool mCleanup; | ||
|
||
public: | ||
ScopedCom(); | ||
~ScopedCom(); | ||
|
||
bool hasError() const; | ||
SystemError error() const; | ||
explicit operator bool() const; | ||
}; | ||
|
||
/*! @endcond */ | ||
} | ||
#endif // QX_WINDOWS_COMMON_P_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters