From 0099e38a9a9ffcc283393625d0096bd8338b81d6 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 5 Oct 2020 14:21:03 -0400 Subject: [PATCH] url: More win32 fixes. --- src/misc/windows/SDL_sysurl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/misc/windows/SDL_sysurl.c b/src/misc/windows/SDL_sysurl.c index 95c450546..a6bdc07e3 100644 --- a/src/misc/windows/SDL_sysurl.c +++ b/src/misc/windows/SDL_sysurl.c @@ -23,20 +23,30 @@ #include "../../core/windows/SDL_windows.h" #include "SDL_error.h" +#include + /* https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx */ int SDL_SYS_OpenURL(const char *url) { + /* MSDN says for safety's sake, make sure COM is initialized. */ + const HRESULT hr = WIN_CoInitialize(); + if (FAILED(hr)) { + return WIN_SetErrorFromHRESULT("CoInitialize failed", hr); + } + WCHAR* wurl = WIN_UTF8ToString(url); int rc; if (wurl == NULL) { + WIN_CoUninitialize(); return SDL_OutOfMemory(); } /* Success returns value greater than 32. Less is an error. */ rc = (int) ShellExecuteW(NULL, L"open", wurl, NULL, NULL, SW_SHOWNORMAL); SDL_free(wurl); + WIN_CoUninitialize(); return (rc > 32) ? 0 : WIN_SetError("Couldn't open given URL."); }