author  Ryan C. Gordon <icculus@icculus.org> 
Wed, 03 Aug 2011 04:22:47 0400  
changeset 5591  17beb16fa838 
parent 5535  96594ac5fd1a 
child 5598  4d05ee9088b1 
permissions  rwrr 
5090
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

1 
/* 
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

2 
Simple DirectMedia Layer 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

3 
Copyright (C) 19972011 Sam Lantinga <slouken@libsdl.org> 
5090
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

4 

5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

5 
This software is provided 'asis', without any express or implied 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

6 
warranty. In no event will the authors be held liable for any damages 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

7 
arising from the use of this software. 
5090
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

8 

5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

9 
Permission is granted to anyone to use this software for any purpose, 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

10 
including commercial applications, and to alter it and redistribute it 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

11 
freely, subject to the following restrictions: 
5090
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

12 

5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

13 
1. The origin of this software must not be misrepresented; you must not 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

14 
claim that you wrote the original software. If you use this software 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

15 
in a product, an acknowledgment in the product documentation would be 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

16 
appreciated but is not required. 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

17 
2. Altered source versions must be plainly marked as such, and must not be 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

18 
misrepresented as being the original software. 
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset

19 
3. This notice may not be removed or altered from any source distribution. 
5090
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

20 
*/ 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

21 
#include "SDL_config.h" 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

22 

327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

23 
#include "SDL_error.h" 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

24 
#include "SDL_windows.h" 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

25 

5591
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

26 
#include <objbase.h> /* for CoInitialize/CoUninitialize */ 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

27 

5090
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

28 

327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

29 
/* Sets an error message based on GetLastError() */ 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

30 
void 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

31 
WIN_SetError(const char *prefix) 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

32 
{ 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

33 
TCHAR buffer[1024]; 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

34 
char *message; 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

35 
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

36 
buffer, SDL_arraysize(buffer), NULL); 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

37 
message = WIN_StringToUTF8(buffer); 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

38 
SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

39 
SDL_free(message); 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

40 
} 
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

41 

5591
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

42 
HRESULT 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

43 
WIN_CoInitialize(void) 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

44 
{ 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

45 
/* S_FALSE means success, but someone else already initialized. */ 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

46 
/* You still need to call CoUninitialize in this case! */ 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

47 
const HRESULT hr = CoInitialize(NULL); 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

48 
if ((hr == S_OK)  (hr == S_FALSE)) { 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

49 
return S_OK; 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

50 
} 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

51 

17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

52 
return hr; 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

53 
} 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

54 

17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

55 
void 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

56 
WIN_CoUninitialize(void) 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

57 
{ 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

58 
CoUninitialize(); 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

59 
} 
17beb16fa838
Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset

60 

5090
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

61 
/* vi: set ts=4 sw=4 expandtab: */ 