-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// LAF Base Library | ||
// Copyright (c) 2024 Igara Studio S.A. | ||
// | ||
// This file is released under the terms of the MIT license. | ||
// Read LICENSE.txt for more information. | ||
|
||
#ifndef BASE_WIN_COINIT_H_INCLUDED | ||
#define BASE_WIN_COINIT_H_INCLUDED | ||
#pragma once | ||
|
||
#if !LAF_WINDOWS | ||
#error This header file can be used only on Windows platform | ||
#endif | ||
|
||
#include <objbase.h> | ||
|
||
namespace base { | ||
|
||
// 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(); | ||
} | ||
}; | ||
|
||
} // namespace base | ||
|
||
#endif |