Skip to content

Commit

Permalink
[win] Minor change to call CoInitialize()/CoUninitialize()
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Aug 12, 2020
1 parent 6987a15 commit 955d0a9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ namespace {
#endif
};

#ifdef _WIN32
// Successful calls to CoInitialize() (S_OK or S_FALSE) must match
// the calls to CoUninitialize().
// From: https://docs.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-couninitialize#remarks
struct CoInit {
HRESULT hr;
CoInit() {
hr = CoInitialize(nullptr);
}
~CoInit() {
if (hr == S_OK || hr == S_FALSE)
CoUninitialize();
}
};
#endif

}

// Aseprite entry point. (Called from "os" library.)
Expand All @@ -59,7 +75,7 @@ int app_main(int argc, char* argv[])
std::srand(static_cast<unsigned int>(std::time(nullptr)));

#ifdef _WIN32
::CoInitialize(nullptr);
CoInit com; // To create COM objects
#endif

try {
Expand Down

0 comments on commit 955d0a9

Please sign in to comment.