Cleaned up CoInitialize() politics on Windows.
This commit is contained in:
parent
0dea877a78
commit
8fa65eea5c
5 changed files with 60 additions and 8 deletions
|
@ -23,6 +23,8 @@
|
|||
#include "SDL_error.h"
|
||||
#include "SDL_windows.h"
|
||||
|
||||
#include <objbase.h> /* for CoInitialize/CoUninitialize */
|
||||
|
||||
|
||||
/* Sets an error message based on GetLastError() */
|
||||
void
|
||||
|
@ -37,4 +39,23 @@ WIN_SetError(const char *prefix)
|
|||
SDL_free(message);
|
||||
}
|
||||
|
||||
HRESULT
|
||||
WIN_CoInitialize(void)
|
||||
{
|
||||
/* S_FALSE means success, but someone else already initialized. */
|
||||
/* You still need to call CoUninitialize in this case! */
|
||||
const HRESULT hr = CoInitialize(NULL);
|
||||
if ((hr == S_OK) || (hr == S_FALSE)) {
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
void
|
||||
WIN_CoUninitialize(void)
|
||||
{
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -47,6 +47,10 @@
|
|||
/* Sets an error message based on GetLastError() */
|
||||
extern void WIN_SetError(const char *prefix);
|
||||
|
||||
/* Wrap up the oddities of CoInitialize() into a common function. */
|
||||
extern HRESULT WIN_CoInitialize(void);
|
||||
extern void WIN_CoUninitialize(void);
|
||||
|
||||
#endif /* _INCLUDED_WINDOWS_H */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue