Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/video/windows/SDL_windowsvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,21 @@ static void WIN_InitDPIAwareness(SDL_VideoDevice *_this)
int WIN_VideoInit(SDL_VideoDevice *_this)
{
SDL_VideoData *data = _this->internal;
HRESULT hr;

hr = WIN_CoInitialize();
if (SUCCEEDED(hr)) {
data->coinitialized = SDL_TRUE;

hr = OleInitialize(NULL);
if (SUCCEEDED(hr)) {
data->oleinitialized = SDL_TRUE;
} else {
SDL_LogInfo(SDL_LOG_CATEGORY_VIDEO, "OleInitialize() failed: 0x%.8x, using fallback drag-n-drop functionality\n", (unsigned int)hr);
}
} else {
SDL_LogInfo(SDL_LOG_CATEGORY_VIDEO, "CoInitialize() failed: 0x%.8x, using fallback drag-n-drop functionality\n", (unsigned int)hr);
}

WIN_InitDPIAwareness(_this);

Expand Down Expand Up @@ -511,6 +526,8 @@ int WIN_VideoInit(SDL_VideoDevice *_this)

void WIN_VideoQuit(SDL_VideoDevice *_this)
{
SDL_VideoData *data = _this->internal;

#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
WIN_QuitModes(_this);
WIN_QuitDeviceNotification();
Expand All @@ -525,6 +542,15 @@ void WIN_VideoQuit(SDL_VideoDevice *_this)

WIN_SetRawMouseEnabled(_this, SDL_FALSE);
WIN_SetRawKeyboardEnabled(_this, SDL_FALSE);

if (data->oleinitialized) {
OleUninitialize();
data->oleinitialized = SDL_FALSE;
}
if (data->coinitialized) {
WIN_CoUninitialize();
data->coinitialized = SDL_FALSE;
}
}

#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
Expand Down
3 changes: 3 additions & 0 deletions src/video/windows/SDL_windowsvideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ struct SDL_VideoData
{
int render;

SDL_bool coinitialized;
SDL_bool oleinitialized;

DWORD clipboard_count;

#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) /* Xbox doesn't support user32/shcore*/
Expand Down
Loading