Debian Codegraph @

src/win/wthread.c

raw
1 /* ______ ___ ___
2 * /\ _ \ /\_ \ /\_ \
3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8 * /\____/
9 * \_/__/
10 *
11 * Thread management.
12 *
13 * By Stefan Schimanski.
14 *
15 * Synchronization functions added by Eric Botcazou.
16 *
17 * See readme.txt for copyright information.
18 */
19
20
21 #include "allegro5/allegro.h"
22 #include "allegro5/internal/aintern.h"
23 #include "allegro5/platform/aintwin.h"
24
25 #include <objbase.h>
26
27 #ifndef ALLEGRO_WINDOWS
28 #error something is wrong with the makefile
29 #endif
30
31 ALLEGRO_DEBUG_CHANNEL("system")
32
33
34 /* COINIT_MULTITHREADED is not defined in objbase.h for MSVC */
35 #define _COINIT_MULTITHREADED 0
36
37 typedef HRESULT(CALLBACK * _CoInitializeEx_ptr) (LPVOID, DWORD);
38 static _CoInitializeEx_ptr _CoInitializeEx = NULL;
39 static int first_call = 1;
40
41
42
43 /* _al_win_thread_init:
44 * Initializes COM interface for the calling thread.
45 * Attempts to use Distributed COM if available (installed by default
46 * on every 32-bit Windows starting with Win98 and Win NT4).
47 */
48 void _al_win_thread_init(void)
49 {
50 HMODULE ole32 = NULL;
51
52 if (first_call) {
53 first_call = 0;
54
55 ole32 = GetModuleHandle(TEXT("OLE32.DLL"));
56 if (ole32 != NULL) {
57 _CoInitializeEx = (_CoInitializeEx_ptr) GetProcAddress(
58 ole32, "CoInitializeEx");
59 }
60 else {
61 ALLEGRO_WARN("OLE32.DLL can't be loaded.\n");
62 }
63
64 if (_CoInitializeEx == NULL) {
65 ALLEGRO_WARN("Microsoft Distributed COM is not installed on this system. If you have problems ");
66 ALLEGRO_WARN("with this application, please install the DCOM update. You can find it on the ");
67 ALLEGRO_WARN("Microsoft homepage\n");
68 }
69 }
70
71 if (_CoInitializeEx != NULL)
72 _CoInitializeEx(NULL, _COINIT_MULTITHREADED);
73 else
74 CoInitialize(NULL);
75 }
76
77
78
79 /* _al_win_thread_exit:
80 * Shuts down COM interface for the calling thread.
81 */
82 void _al_win_thread_exit(void)
83 {
84 CoUninitialize();
85 }
86
87