Debian Codegraph @

terps/tads/tads3/win32/osnet-fgwin.cpp

raw
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header$";
4 #endif
5
6 /* Copyright (c) 2010 by Michael J. Roberts. All Rights Reserved. */
7 /*
8 Name
9 osnet-fgwin.cpp - AllowSetForegroundWindow interface glue
10 Function
11 Defines a cover function for AllowSetForegroundWindow that links
12 dynamically to USER32.DLL, so that we can call the function where
13 available but still work on older Windows versions that don't
14 export the function.
15 Notes
16
17 Modified
18 05/12/10 MJRoberts - Creation
19 */
20
21 #include <string.h>
22 #include <stdlib.h>
23 #include "t3std.h"
24 #include "os.h"
25 #include "osifcnet.h"
26
27
28 /* ------------------------------------------------------------------------ */
29 /*
30 * Run-time imports, for functions that aren't available in all Windows
31 * version that we wish to support.
32 */
33 static BOOL (WINAPI *pAllowSetForegroundWindow)(DWORD) = 0;
34 static int checked_imports = FALSE;
35 static HINSTANCE hUser32 = 0;
36 static void check_imports()
37 {
38 if (!checked_imports)
39 {
40 checked_imports = TRUE;
41 if ((hUser32 = LoadLibrary("USER32.DLL")) != 0)
42 {
43 pAllowSetForegroundWindow =
44 (BOOL (WINAPI *)(DWORD))GetProcAddress(
45 hUser32, "AllowSetForegroundWindow");
46 }
47 }
48 }
49
50 /* AllowSetForegroundWindow cover (it's only in Win2k and up) */
51 BOOL tads_AllowSetForegroundWindow(DWORD pid)
52 {
53 check_imports();
54 if (pAllowSetForegroundWindow != 0)
55 return (*pAllowSetForegroundWindow)(pid);
56 else
57 return FALSE;
58 }
59
60 /* unlink USER32.DLL, if we loaded it */
61 void tads_unlink_user32()
62 {
63 /* unload dynamically loaded libraries */
64 if (hUser32 != 0)
65 FreeLibrary(hUser32);
66 }