win32_init.c
Go to the documentation of this file.
1 //========================================================================
2 // GLFW 3.3 Win32 - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org>
6 //
7 // This software is provided 'as-is', without any express or implied
8 // warranty. In no event will the authors be held liable for any damages
9 // arising from the use of this software.
10 //
11 // Permission is granted to anyone to use this software for any purpose,
12 // including commercial applications, and to alter it and redistribute it
13 // freely, subject to the following restrictions:
14 //
15 // 1. The origin of this software must not be misrepresented; you must not
16 // claim that you wrote the original software. If you use this software
17 // in a product, an acknowledgment in the product documentation would
18 // be appreciated but is not required.
19 //
20 // 2. Altered source versions must be plainly marked as such, and must not
21 // be misrepresented as being the original software.
22 //
23 // 3. This notice may not be removed or altered from any source
24 // distribution.
25 //
26 //========================================================================
27 
28 #include "internal.h"
29 
30 #include <stdlib.h>
31 #include <malloc.h>
32 
34  {0x4d1e55b2,0xf16f,0x11cf,{0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30}};
35 
36 #define GUID_DEVINTERFACE_HID _glfw_GUID_DEVINTERFACE_HID
37 
38 #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
39 
40 // Executables (but not DLLs) exporting this symbol with this value will be
41 // automatically directed to the high-performance GPU on Nvidia Optimus systems
42 // with up-to-date drivers
43 //
44 __declspec(dllexport) DWORD NvOptimusEnablement = 1;
45 
46 // Executables (but not DLLs) exporting this symbol with this value will be
47 // automatically directed to the high-performance GPU on AMD PowerXpress systems
48 // with up-to-date drivers
49 //
50 __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
51 
52 #endif // _GLFW_USE_HYBRID_HPG
53 
54 #if defined(_GLFW_BUILD_DLL)
55 
56 // GLFW DLL entry point
57 //
58 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
59 {
60  return TRUE;
61 }
62 
63 #endif // _GLFW_BUILD_DLL
64 
65 // Load necessary libraries (DLLs)
66 //
67 static GLFWbool loadLibraries(void)
68 {
69  _glfw.win32.winmm.instance = LoadLibraryA("winmm.dll");
70  if (!_glfw.win32.winmm.instance)
71  {
73  "Win32: Failed to load winmm.dll");
74  return GLFW_FALSE;
75  }
76 
77  _glfw.win32.winmm.GetTime = (PFN_timeGetTime)
78  GetProcAddress(_glfw.win32.winmm.instance, "timeGetTime");
79 
80  _glfw.win32.user32.instance = LoadLibraryA("user32.dll");
81  if (!_glfw.win32.user32.instance)
82  {
84  "Win32: Failed to load user32.dll");
85  return GLFW_FALSE;
86  }
87 
88  _glfw.win32.user32.SetProcessDPIAware_ = (PFN_SetProcessDPIAware)
89  GetProcAddress(_glfw.win32.user32.instance, "SetProcessDPIAware");
90  _glfw.win32.user32.ChangeWindowMessageFilterEx_ = (PFN_ChangeWindowMessageFilterEx)
91  GetProcAddress(_glfw.win32.user32.instance, "ChangeWindowMessageFilterEx");
92  _glfw.win32.user32.EnableNonClientDpiScaling_ = (PFN_EnableNonClientDpiScaling)
93  GetProcAddress(_glfw.win32.user32.instance, "EnableNonClientDpiScaling");
94  _glfw.win32.user32.SetProcessDpiAwarenessContext_ = (PFN_SetProcessDpiAwarenessContext)
95  GetProcAddress(_glfw.win32.user32.instance, "SetProcessDpiAwarenessContext");
96  _glfw.win32.user32.GetDpiForWindow_ = (PFN_GetDpiForWindow)
97  GetProcAddress(_glfw.win32.user32.instance, "GetDpiForWindow");
98  _glfw.win32.user32.AdjustWindowRectExForDpi_ = (PFN_AdjustWindowRectExForDpi)
99  GetProcAddress(_glfw.win32.user32.instance, "AdjustWindowRectExForDpi");
100 
101  _glfw.win32.dinput8.instance = LoadLibraryA("dinput8.dll");
102  if (_glfw.win32.dinput8.instance)
103  {
104  _glfw.win32.dinput8.Create = (PFN_DirectInput8Create)
105  GetProcAddress(_glfw.win32.dinput8.instance, "DirectInput8Create");
106  }
107 
108  {
109  int i;
110  const char* names[] =
111  {
112  "xinput1_4.dll",
113  "xinput1_3.dll",
114  "xinput9_1_0.dll",
115  "xinput1_2.dll",
116  "xinput1_1.dll",
117  NULL
118  };
119 
120  for (i = 0; names[i]; i++)
121  {
122  _glfw.win32.xinput.instance = LoadLibraryA(names[i]);
123  if (_glfw.win32.xinput.instance)
124  {
125  _glfw.win32.xinput.GetCapabilities = (PFN_XInputGetCapabilities)
126  GetProcAddress(_glfw.win32.xinput.instance, "XInputGetCapabilities");
127  _glfw.win32.xinput.GetState = (PFN_XInputGetState)
128  GetProcAddress(_glfw.win32.xinput.instance, "XInputGetState");
129 
130  break;
131  }
132  }
133  }
134 
135  _glfw.win32.dwmapi.instance = LoadLibraryA("dwmapi.dll");
136  if (_glfw.win32.dwmapi.instance)
137  {
138  _glfw.win32.dwmapi.IsCompositionEnabled = (PFN_DwmIsCompositionEnabled)
139  GetProcAddress(_glfw.win32.dwmapi.instance, "DwmIsCompositionEnabled");
140  _glfw.win32.dwmapi.Flush = (PFN_DwmFlush)
141  GetProcAddress(_glfw.win32.dwmapi.instance, "DwmFlush");
142  _glfw.win32.dwmapi.EnableBlurBehindWindow = (PFN_DwmEnableBlurBehindWindow)
143  GetProcAddress(_glfw.win32.dwmapi.instance, "DwmEnableBlurBehindWindow");
144  }
145 
146  _glfw.win32.shcore.instance = LoadLibraryA("shcore.dll");
147  if (_glfw.win32.shcore.instance)
148  {
149  _glfw.win32.shcore.SetProcessDpiAwareness_ = (PFN_SetProcessDpiAwareness)
150  GetProcAddress(_glfw.win32.shcore.instance, "SetProcessDpiAwareness");
151  _glfw.win32.shcore.GetDpiForMonitor_ = (PFN_GetDpiForMonitor)
152  GetProcAddress(_glfw.win32.shcore.instance, "GetDpiForMonitor");
153  }
154 
155  _glfw.win32.ntdll.instance = LoadLibraryA("ntdll.dll");
156  if (_glfw.win32.ntdll.instance)
157  {
158  _glfw.win32.ntdll.RtlVerifyVersionInfo_ = (PFN_RtlVerifyVersionInfo)
159  GetProcAddress(_glfw.win32.ntdll.instance, "RtlVerifyVersionInfo");
160  }
161 
162  return GLFW_TRUE;
163 }
164 
165 // Unload used libraries (DLLs)
166 //
167 static void freeLibraries(void)
168 {
169  if (_glfw.win32.xinput.instance)
170  FreeLibrary(_glfw.win32.xinput.instance);
171 
172  if (_glfw.win32.dinput8.instance)
173  FreeLibrary(_glfw.win32.dinput8.instance);
174 
175  if (_glfw.win32.winmm.instance)
176  FreeLibrary(_glfw.win32.winmm.instance);
177 
178  if (_glfw.win32.user32.instance)
179  FreeLibrary(_glfw.win32.user32.instance);
180 
181  if (_glfw.win32.dwmapi.instance)
182  FreeLibrary(_glfw.win32.dwmapi.instance);
183 
184  if (_glfw.win32.shcore.instance)
185  FreeLibrary(_glfw.win32.shcore.instance);
186 
187  if (_glfw.win32.ntdll.instance)
188  FreeLibrary(_glfw.win32.ntdll.instance);
189 }
190 
191 // Create key code translation tables
192 //
193 static void createKeyTables(void)
194 {
195  int scancode;
196 
197  memset(_glfw.win32.keycodes, -1, sizeof(_glfw.win32.keycodes));
198  memset(_glfw.win32.scancodes, -1, sizeof(_glfw.win32.scancodes));
199 
200  _glfw.win32.keycodes[0x00B] = GLFW_KEY_0;
201  _glfw.win32.keycodes[0x002] = GLFW_KEY_1;
202  _glfw.win32.keycodes[0x003] = GLFW_KEY_2;
203  _glfw.win32.keycodes[0x004] = GLFW_KEY_3;
204  _glfw.win32.keycodes[0x005] = GLFW_KEY_4;
205  _glfw.win32.keycodes[0x006] = GLFW_KEY_5;
206  _glfw.win32.keycodes[0x007] = GLFW_KEY_6;
207  _glfw.win32.keycodes[0x008] = GLFW_KEY_7;
208  _glfw.win32.keycodes[0x009] = GLFW_KEY_8;
209  _glfw.win32.keycodes[0x00A] = GLFW_KEY_9;
210  _glfw.win32.keycodes[0x01E] = GLFW_KEY_A;
211  _glfw.win32.keycodes[0x030] = GLFW_KEY_B;
212  _glfw.win32.keycodes[0x02E] = GLFW_KEY_C;
213  _glfw.win32.keycodes[0x020] = GLFW_KEY_D;
214  _glfw.win32.keycodes[0x012] = GLFW_KEY_E;
215  _glfw.win32.keycodes[0x021] = GLFW_KEY_F;
216  _glfw.win32.keycodes[0x022] = GLFW_KEY_G;
217  _glfw.win32.keycodes[0x023] = GLFW_KEY_H;
218  _glfw.win32.keycodes[0x017] = GLFW_KEY_I;
219  _glfw.win32.keycodes[0x024] = GLFW_KEY_J;
220  _glfw.win32.keycodes[0x025] = GLFW_KEY_K;
221  _glfw.win32.keycodes[0x026] = GLFW_KEY_L;
222  _glfw.win32.keycodes[0x032] = GLFW_KEY_M;
223  _glfw.win32.keycodes[0x031] = GLFW_KEY_N;
224  _glfw.win32.keycodes[0x018] = GLFW_KEY_O;
225  _glfw.win32.keycodes[0x019] = GLFW_KEY_P;
226  _glfw.win32.keycodes[0x010] = GLFW_KEY_Q;
227  _glfw.win32.keycodes[0x013] = GLFW_KEY_R;
228  _glfw.win32.keycodes[0x01F] = GLFW_KEY_S;
229  _glfw.win32.keycodes[0x014] = GLFW_KEY_T;
230  _glfw.win32.keycodes[0x016] = GLFW_KEY_U;
231  _glfw.win32.keycodes[0x02F] = GLFW_KEY_V;
232  _glfw.win32.keycodes[0x011] = GLFW_KEY_W;
233  _glfw.win32.keycodes[0x02D] = GLFW_KEY_X;
234  _glfw.win32.keycodes[0x015] = GLFW_KEY_Y;
235  _glfw.win32.keycodes[0x02C] = GLFW_KEY_Z;
236 
237  _glfw.win32.keycodes[0x028] = GLFW_KEY_APOSTROPHE;
238  _glfw.win32.keycodes[0x02B] = GLFW_KEY_BACKSLASH;
239  _glfw.win32.keycodes[0x033] = GLFW_KEY_COMMA;
240  _glfw.win32.keycodes[0x00D] = GLFW_KEY_EQUAL;
241  _glfw.win32.keycodes[0x029] = GLFW_KEY_GRAVE_ACCENT;
242  _glfw.win32.keycodes[0x01A] = GLFW_KEY_LEFT_BRACKET;
243  _glfw.win32.keycodes[0x00C] = GLFW_KEY_MINUS;
244  _glfw.win32.keycodes[0x034] = GLFW_KEY_PERIOD;
245  _glfw.win32.keycodes[0x01B] = GLFW_KEY_RIGHT_BRACKET;
246  _glfw.win32.keycodes[0x027] = GLFW_KEY_SEMICOLON;
247  _glfw.win32.keycodes[0x035] = GLFW_KEY_SLASH;
248  _glfw.win32.keycodes[0x056] = GLFW_KEY_WORLD_2;
249 
250  _glfw.win32.keycodes[0x00E] = GLFW_KEY_BACKSPACE;
251  _glfw.win32.keycodes[0x153] = GLFW_KEY_DELETE;
252  _glfw.win32.keycodes[0x14F] = GLFW_KEY_END;
253  _glfw.win32.keycodes[0x01C] = GLFW_KEY_ENTER;
254  _glfw.win32.keycodes[0x001] = GLFW_KEY_ESCAPE;
255  _glfw.win32.keycodes[0x147] = GLFW_KEY_HOME;
256  _glfw.win32.keycodes[0x152] = GLFW_KEY_INSERT;
257  _glfw.win32.keycodes[0x15D] = GLFW_KEY_MENU;
258  _glfw.win32.keycodes[0x151] = GLFW_KEY_PAGE_DOWN;
259  _glfw.win32.keycodes[0x149] = GLFW_KEY_PAGE_UP;
260  _glfw.win32.keycodes[0x045] = GLFW_KEY_PAUSE;
261  _glfw.win32.keycodes[0x146] = GLFW_KEY_PAUSE;
262  _glfw.win32.keycodes[0x039] = GLFW_KEY_SPACE;
263  _glfw.win32.keycodes[0x00F] = GLFW_KEY_TAB;
264  _glfw.win32.keycodes[0x03A] = GLFW_KEY_CAPS_LOCK;
265  _glfw.win32.keycodes[0x145] = GLFW_KEY_NUM_LOCK;
266  _glfw.win32.keycodes[0x046] = GLFW_KEY_SCROLL_LOCK;
267  _glfw.win32.keycodes[0x03B] = GLFW_KEY_F1;
268  _glfw.win32.keycodes[0x03C] = GLFW_KEY_F2;
269  _glfw.win32.keycodes[0x03D] = GLFW_KEY_F3;
270  _glfw.win32.keycodes[0x03E] = GLFW_KEY_F4;
271  _glfw.win32.keycodes[0x03F] = GLFW_KEY_F5;
272  _glfw.win32.keycodes[0x040] = GLFW_KEY_F6;
273  _glfw.win32.keycodes[0x041] = GLFW_KEY_F7;
274  _glfw.win32.keycodes[0x042] = GLFW_KEY_F8;
275  _glfw.win32.keycodes[0x043] = GLFW_KEY_F9;
276  _glfw.win32.keycodes[0x044] = GLFW_KEY_F10;
277  _glfw.win32.keycodes[0x057] = GLFW_KEY_F11;
278  _glfw.win32.keycodes[0x058] = GLFW_KEY_F12;
279  _glfw.win32.keycodes[0x064] = GLFW_KEY_F13;
280  _glfw.win32.keycodes[0x065] = GLFW_KEY_F14;
281  _glfw.win32.keycodes[0x066] = GLFW_KEY_F15;
282  _glfw.win32.keycodes[0x067] = GLFW_KEY_F16;
283  _glfw.win32.keycodes[0x068] = GLFW_KEY_F17;
284  _glfw.win32.keycodes[0x069] = GLFW_KEY_F18;
285  _glfw.win32.keycodes[0x06A] = GLFW_KEY_F19;
286  _glfw.win32.keycodes[0x06B] = GLFW_KEY_F20;
287  _glfw.win32.keycodes[0x06C] = GLFW_KEY_F21;
288  _glfw.win32.keycodes[0x06D] = GLFW_KEY_F22;
289  _glfw.win32.keycodes[0x06E] = GLFW_KEY_F23;
290  _glfw.win32.keycodes[0x076] = GLFW_KEY_F24;
291  _glfw.win32.keycodes[0x038] = GLFW_KEY_LEFT_ALT;
292  _glfw.win32.keycodes[0x01D] = GLFW_KEY_LEFT_CONTROL;
293  _glfw.win32.keycodes[0x02A] = GLFW_KEY_LEFT_SHIFT;
294  _glfw.win32.keycodes[0x15B] = GLFW_KEY_LEFT_SUPER;
295  _glfw.win32.keycodes[0x137] = GLFW_KEY_PRINT_SCREEN;
296  _glfw.win32.keycodes[0x138] = GLFW_KEY_RIGHT_ALT;
297  _glfw.win32.keycodes[0x11D] = GLFW_KEY_RIGHT_CONTROL;
298  _glfw.win32.keycodes[0x036] = GLFW_KEY_RIGHT_SHIFT;
299  _glfw.win32.keycodes[0x15C] = GLFW_KEY_RIGHT_SUPER;
300  _glfw.win32.keycodes[0x150] = GLFW_KEY_DOWN;
301  _glfw.win32.keycodes[0x14B] = GLFW_KEY_LEFT;
302  _glfw.win32.keycodes[0x14D] = GLFW_KEY_RIGHT;
303  _glfw.win32.keycodes[0x148] = GLFW_KEY_UP;
304 
305  _glfw.win32.keycodes[0x052] = GLFW_KEY_KP_0;
306  _glfw.win32.keycodes[0x04F] = GLFW_KEY_KP_1;
307  _glfw.win32.keycodes[0x050] = GLFW_KEY_KP_2;
308  _glfw.win32.keycodes[0x051] = GLFW_KEY_KP_3;
309  _glfw.win32.keycodes[0x04B] = GLFW_KEY_KP_4;
310  _glfw.win32.keycodes[0x04C] = GLFW_KEY_KP_5;
311  _glfw.win32.keycodes[0x04D] = GLFW_KEY_KP_6;
312  _glfw.win32.keycodes[0x047] = GLFW_KEY_KP_7;
313  _glfw.win32.keycodes[0x048] = GLFW_KEY_KP_8;
314  _glfw.win32.keycodes[0x049] = GLFW_KEY_KP_9;
315  _glfw.win32.keycodes[0x04E] = GLFW_KEY_KP_ADD;
316  _glfw.win32.keycodes[0x053] = GLFW_KEY_KP_DECIMAL;
317  _glfw.win32.keycodes[0x135] = GLFW_KEY_KP_DIVIDE;
318  _glfw.win32.keycodes[0x11C] = GLFW_KEY_KP_ENTER;
319  _glfw.win32.keycodes[0x059] = GLFW_KEY_KP_EQUAL;
320  _glfw.win32.keycodes[0x037] = GLFW_KEY_KP_MULTIPLY;
321  _glfw.win32.keycodes[0x04A] = GLFW_KEY_KP_SUBTRACT;
322 
323  for (scancode = 0; scancode < 512; scancode++)
324  {
325  if (_glfw.win32.keycodes[scancode] > 0)
326  _glfw.win32.scancodes[_glfw.win32.keycodes[scancode]] = scancode;
327  }
328 }
329 
330 // Creates a dummy window for behind-the-scenes work
331 //
332 static HWND createHelperWindow(void)
333 {
334  MSG msg;
335  HWND window = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
337  L"GLFW message window",
338  WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
339  0, 0, 1, 1,
340  NULL, NULL,
341  GetModuleHandleW(NULL),
342  NULL);
343  if (!window)
344  {
346  "Win32: Failed to create helper window");
347  return NULL;
348  }
349 
350  // HACK: The command to the first ShowWindow call is ignored if the parent
351  // process passed along a STARTUPINFO, so clear that with a no-op call
352  ShowWindow(window, SW_HIDE);
353 
354  // Register for HID device notifications
355  {
356  DEV_BROADCAST_DEVICEINTERFACE_W dbi;
357  ZeroMemory(&dbi, sizeof(dbi));
358  dbi.dbcc_size = sizeof(dbi);
359  dbi.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
360  dbi.dbcc_classguid = GUID_DEVINTERFACE_HID;
361 
362  _glfw.win32.deviceNotificationHandle =
363  RegisterDeviceNotificationW(window,
364  (DEV_BROADCAST_HDR*) &dbi,
365  DEVICE_NOTIFY_WINDOW_HANDLE);
366  }
367 
368  while (PeekMessageW(&msg, _glfw.win32.helperWindowHandle, 0, 0, PM_REMOVE))
369  {
370  TranslateMessage(&msg);
371  DispatchMessageW(&msg);
372  }
373 
374  return window;
375 }
376 
377 
381 
382 // Returns a wide string version of the specified UTF-8 string
383 //
385 {
386  WCHAR* target;
387  int count;
388 
389  count = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0);
390  if (!count)
391  {
393  "Win32: Failed to convert string from UTF-8");
394  return NULL;
395  }
396 
397  target = calloc(count, sizeof(WCHAR));
398 
399  if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, count))
400  {
402  "Win32: Failed to convert string from UTF-8");
403  free(target);
404  return NULL;
405  }
406 
407  return target;
408 }
409 
410 // Returns a UTF-8 string version of the specified wide string
411 //
413 {
414  char* target;
415  int size;
416 
417  size = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
418  if (!size)
419  {
421  "Win32: Failed to convert string to UTF-8");
422  return NULL;
423  }
424 
425  target = calloc(size, 1);
426 
427  if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, size, NULL, NULL))
428  {
430  "Win32: Failed to convert string to UTF-8");
431  free(target);
432  return NULL;
433  }
434 
435  return target;
436 }
437 
438 // Reports the specified error, appending information about the last Win32 error
439 //
440 void _glfwInputErrorWin32(int error, const char* description)
441 {
442  WCHAR buffer[_GLFW_MESSAGE_SIZE] = L"";
443  char message[_GLFW_MESSAGE_SIZE] = "";
444 
445  FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
446  FORMAT_MESSAGE_IGNORE_INSERTS |
447  FORMAT_MESSAGE_MAX_WIDTH_MASK,
448  NULL,
449  GetLastError() & 0xffff,
450  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
451  buffer,
452  sizeof(buffer),
453  NULL);
454  WideCharToMultiByte(CP_UTF8, 0, buffer, -1, message, sizeof(message), NULL, NULL);
455 
456  _glfwInputError(error, "%s: %s", description, message);
457 }
458 
459 // Updates key names according to the current keyboard layout
460 //
462 {
463  int key;
464  BYTE state[256] = {0};
465 
466  memset(_glfw.win32.keynames, 0, sizeof(_glfw.win32.keynames));
467 
468  for (key = GLFW_KEY_SPACE; key <= GLFW_KEY_LAST; key++)
469  {
470  UINT vk;
471  int scancode, length;
472  WCHAR chars[16];
473 
474  scancode = _glfw.win32.scancodes[key];
475  if (scancode == -1)
476  continue;
477 
478  if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_ADD)
479  {
480  const UINT vks[] = {
481  VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
482  VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
483  VK_NUMPAD8, VK_NUMPAD9, VK_DECIMAL, VK_DIVIDE,
484  VK_MULTIPLY, VK_SUBTRACT, VK_ADD
485  };
486 
487  vk = vks[key - GLFW_KEY_KP_0];
488  }
489  else
490  vk = MapVirtualKey(scancode, MAPVK_VSC_TO_VK);
491 
492  length = ToUnicode(vk, scancode, state,
493  chars, sizeof(chars) / sizeof(WCHAR),
494  0);
495 
496  if (length == -1)
497  {
498  length = ToUnicode(vk, scancode, state,
499  chars, sizeof(chars) / sizeof(WCHAR),
500  0);
501  }
502 
503  if (length < 1)
504  continue;
505 
506  WideCharToMultiByte(CP_UTF8, 0, chars, 1,
507  _glfw.win32.keynames[key],
508  sizeof(_glfw.win32.keynames[key]),
509  NULL, NULL);
510  }
511 }
512 
513 // Replacement for IsWindowsVersionOrGreater as MinGW lacks versionhelpers.h
514 //
516 {
517  OSVERSIONINFOEXW osvi = { sizeof(osvi), major, minor, 0, 0, {0}, sp };
518  DWORD mask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR;
519  ULONGLONG cond = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
520  cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);
521  cond = VerSetConditionMask(cond, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
522  // HACK: Use RtlVerifyVersionInfo instead of VerifyVersionInfoW as the
523  // latter lies unless the user knew to embedd a non-default manifest
524  // announcing support for Windows 10 via supportedOS GUID
525  return RtlVerifyVersionInfo(&osvi, mask, cond) == 0;
526 }
527 
528 // Checks whether we are on at least the specified build of Windows 10
529 //
531 {
532  OSVERSIONINFOEXW osvi = { sizeof(osvi), 10, 0, build };
533  DWORD mask = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER;
534  ULONGLONG cond = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
535  cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);
536  cond = VerSetConditionMask(cond, VER_BUILDNUMBER, VER_GREATER_EQUAL);
537  // HACK: Use RtlVerifyVersionInfo instead of VerifyVersionInfoW as the
538  // latter lies unless the user knew to embedd a non-default manifest
539  // announcing support for Windows 10 via supportedOS GUID
540  return RtlVerifyVersionInfo(&osvi, mask, cond) == 0;
541 }
542 
543 
547 
549 {
550  // To make SetForegroundWindow work as we want, we need to fiddle
551  // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
552  // as possible in the hope of still being the foreground process)
553  SystemParametersInfoW(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
554  &_glfw.win32.foregroundLockTimeout, 0);
555  SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0),
556  SPIF_SENDCHANGE);
557 
558  if (!loadLibraries())
559  return GLFW_FALSE;
560 
561  createKeyTables();
563 
566  else if (IsWindows8Point1OrGreater())
568  else if (IsWindowsVistaOrGreater())
570 
572  return GLFW_FALSE;
573 
574  _glfw.win32.helperWindowHandle = createHelperWindow();
575  if (!_glfw.win32.helperWindowHandle)
576  return GLFW_FALSE;
577 
580 
582  return GLFW_TRUE;
583 }
584 
586 {
587  if (_glfw.win32.deviceNotificationHandle)
588  UnregisterDeviceNotification(_glfw.win32.deviceNotificationHandle);
589 
590  if (_glfw.win32.helperWindowHandle)
591  DestroyWindow(_glfw.win32.helperWindowHandle);
592 
594 
595  // Restore previous foreground lock timeout system setting
596  SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
597  UIntToPtr(_glfw.win32.foregroundLockTimeout),
598  SPIF_SENDCHANGE);
599 
600  free(_glfw.win32.clipboardString);
601  free(_glfw.win32.rawInput);
602 
605 
607 
608  freeLibraries();
609 }
610 
612 {
613  return _GLFW_VERSION_NUMBER " Win32 WGL EGL"
614 #if defined(__MINGW32__)
615  " MinGW"
616 #elif defined(_MSC_VER)
617  " VisualC"
618 #endif
619 #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
620  " hybrid-GPU"
621 #endif
622 #if defined(_GLFW_BUILD_DLL)
623  " DLL"
624 #endif
625  ;
626 }
627 
#define GLFW_KEY_SCROLL_LOCK
Definition: glfw3.h:427
#define GLFW_KEY_KP_1
Definition: glfw3.h:457
BOOL(WINAPI * PFN_SetProcessDpiAwarenessContext)(HANDLE)
static void createKeyTables(void)
Definition: win32_init.c:193
GLenum GLuint GLenum GLsizei const GLchar * message
#define GLFW_KEY_F6
Definition: glfw3.h:436
HRESULT(WINAPI * PFN_DwmEnableBlurBehindWindow)(HWND, const DWM_BLURBEHIND *)
#define GLFW_KEY_F14
Definition: glfw3.h:444
#define GLFW_KEY_RIGHT_CONTROL
Definition: glfw3.h:478
WCHAR * _glfwCreateWideStringFromUTF8Win32(const char *source)
Definition: win32_init.c:384
#define GLFW_KEY_INSERT
Definition: glfw3.h:416
#define GLFW_KEY_KP_DIVIDE
Definition: glfw3.h:467
#define GLFW_KEY_LEFT
Definition: glfw3.h:419
#define GLFW_KEY_I
Definition: glfw3.h:386
#define IsWindows8Point1OrGreater()
HRESULT(WINAPI * PFN_DwmFlush)(VOID)
#define GLFW_KEY_F
Definition: glfw3.h:383
HRESULT(WINAPI * PFN_GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *)
#define GLFW_KEY_KP_5
Definition: glfw3.h:461
#define _GLFW_VERSION_NUMBER
Definition: internal.h:199
#define GLFW_KEY_SEMICOLON
Definition: glfw3.h:376
#define GLFW_KEY_KP_3
Definition: glfw3.h:459
#define GLFW_KEY_PERIOD
Definition: glfw3.h:364
static GLFWbool loadLibraries(void)
Definition: win32_init.c:67
static GLFWwindow * window
Definition: joysticks.c:55
void _glfwTerminateJoysticksWin32(void)
#define GLFW_KEY_UP
Definition: glfw3.h:421
#define GLFW_KEY_KP_6
Definition: glfw3.h:462
#define GLFW_KEY_X
Definition: glfw3.h:401
#define GLFW_KEY_6
Definition: glfw3.h:372
GLint GLuint mask
#define GLFW_KEY_GRAVE_ACCENT
Definition: glfw3.h:407
#define GLFW_KEY_SPACE
Definition: glfw3.h:360
#define GLFW_KEY_WORLD_2
Definition: glfw3.h:409
char * _glfwCreateUTF8FromWideStringWin32(const WCHAR *source)
Definition: win32_init.c:412
#define GLFW_KEY_PAUSE
Definition: glfw3.h:430
#define GLFW_KEY_KP_2
Definition: glfw3.h:458
HRESULT(WINAPI * PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS)
#define GLFW_KEY_F7
Definition: glfw3.h:437
#define GLFW_KEY_LEFT_SHIFT
Definition: glfw3.h:473
#define GLFW_FALSE
Zero.
Definition: glfw3.h:287
#define GLFW_KEY_F8
Definition: glfw3.h:438
#define GLFW_KEY_8
Definition: glfw3.h:374
void _glfwPlatformTerminate(void)
Definition: win32_init.c:585
BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp)
Definition: win32_init.c:515
#define SetProcessDpiAwarenessContext
#define GLFW_KEY_P
Definition: glfw3.h:393
#define GLFW_KEY_PAGE_DOWN
Definition: glfw3.h:423
BOOL(WINAPI * PFN_ChangeWindowMessageFilterEx)(HWND, UINT, DWORD, CHANGEFILTERSTRUCT *)
BOOL(WINAPI * PFN_EnableNonClientDpiScaling)(HWND)
#define GLFW_KEY_F2
Definition: glfw3.h:432
#define GLFW_KEY_LEFT_BRACKET
Definition: glfw3.h:404
#define GLFW_KEY_HOME
Definition: glfw3.h:424
#define GLFW_KEY_K
Definition: glfw3.h:388
void _glfwInitTimerWin32(void)
Definition: win32_time.c:37
#define GLFW_KEY_E
Definition: glfw3.h:382
#define GLFW_KEY_PAGE_UP
Definition: glfw3.h:422
int GLFWbool
Definition: internal.h:61
GLenum GLfloat * buffer
#define GLFW_KEY_Z
Definition: glfw3.h:403
DWORD(WINAPI * PFN_XInputGetState)(DWORD, XINPUT_STATE *)
GLuint GLuint * names
Definition: glext.h:5648
#define GLFW_KEY_B
Definition: glfw3.h:379
#define GLFW_KEY_7
Definition: glfw3.h:373
#define GLFW_KEY_BACKSPACE
Definition: glfw3.h:415
#define GLFW_KEY_H
Definition: glfw3.h:385
#define RtlVerifyVersionInfo
#define GLFW_KEY_A
Definition: glfw3.h:378
#define GLFW_KEY_F15
Definition: glfw3.h:445
#define GLFW_KEY_V
Definition: glfw3.h:399
GLuint64 key
Definition: glext.h:8966
#define GLFW_KEY_F13
Definition: glfw3.h:443
UINT(WINAPI * PFN_GetDpiForWindow)(HWND)
#define GLFW_KEY_KP_DECIMAL
Definition: glfw3.h:466
LONG(WINAPI * PFN_RtlVerifyVersionInfo)(OSVERSIONINFOEXW *, ULONG, ULONGLONG)
#define GLFW_KEY_F5
Definition: glfw3.h:435
#define GLFW_KEY_F20
Definition: glfw3.h:450
const char * _glfwPlatformGetVersionString(void)
Definition: win32_init.c:611
#define GLFW_KEY_F9
Definition: glfw3.h:439
#define GLFW_KEY_F10
Definition: glfw3.h:440
#define GLFW_KEY_T
Definition: glfw3.h:397
unsigned char BYTE
Definition: lz4.c:145
#define GLFW_KEY_KP_9
Definition: glfw3.h:465
#define GLFW_KEY_1
Definition: glfw3.h:367
#define GLFW_KEY_RIGHT_SUPER
Definition: glfw3.h:480
#define GUID_DEVINTERFACE_HID
Definition: win32_init.c:36
GLsizeiptr size
#define GLFW_KEY_KP_ADD
Definition: glfw3.h:470
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
Definition: glfw3.h:726
#define GLFW_KEY_END
Definition: glfw3.h:425
_GLFWlibrary _glfw
Definition: init.c:44
#define GLFW_KEY_F11
Definition: glfw3.h:441
#define GLFW_KEY_KP_7
Definition: glfw3.h:463
#define GLFW_KEY_EQUAL
Definition: glfw3.h:377
#define GLFW_KEY_CAPS_LOCK
Definition: glfw3.h:426
#define GLFW_KEY_DELETE
Definition: glfw3.h:417
#define GLFW_KEY_ESCAPE
Definition: glfw3.h:412
BOOL(WINAPI * PFN_AdjustWindowRectExForDpi)(LPRECT, DWORD, BOOL, DWORD, UINT)
#define GLFW_KEY_KP_MULTIPLY
Definition: glfw3.h:468
#define GLFW_KEY_S
Definition: glfw3.h:396
#define GLFW_KEY_F1
Definition: glfw3.h:431
void _glfwInputErrorWin32(int error, const char *description)
Definition: win32_init.c:440
void _glfwTerminateEGL(void)
Definition: egl_context.c:432
#define GLFW_KEY_0
Definition: glfw3.h:366
#define GLFW_KEY_NUM_LOCK
Definition: glfw3.h:428
#define GLFW_KEY_TAB
Definition: glfw3.h:414
DWORD(WINAPI * PFN_XInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES *)
static void freeLibraries(void)
Definition: win32_init.c:167
GLenum target
Definition: glext.h:1565
#define GLFW_KEY_W
Definition: glfw3.h:400
#define GLFW_KEY_U
Definition: glfw3.h:398
#define GLFW_KEY_4
Definition: glfw3.h:370
#define GLFW_KEY_N
Definition: glfw3.h:391
#define GLFW_KEY_F12
Definition: glfw3.h:442
#define GLFW_KEY_F17
Definition: glfw3.h:447
#define GLFW_KEY_KP_4
Definition: glfw3.h:460
#define GLFW_KEY_2
Definition: glfw3.h:368
#define SetProcessDPIAware
#define GLFW_KEY_3
Definition: glfw3.h:369
#define GLFW_KEY_MENU
Definition: glfw3.h:481
#define GLFW_KEY_ENTER
Definition: glfw3.h:413
BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build)
Definition: win32_init.c:530
void _glfwInputError(int code, const char *format,...)
Definition: init.c:129
static const GUID _glfw_GUID_DEVINTERFACE_HID
Definition: win32_init.c:33
int _glfwPlatformInit(void)
Definition: win32_init.c:548
void _glfwPollMonitorsWin32(void)
void _glfwInitJoysticksWin32(void)
#define GLFW_KEY_G
Definition: glfw3.h:384
#define GLFW_KEY_D
Definition: glfw3.h:381
#define IsWindowsVistaOrGreater()
void _glfwUnregisterWindowClassWin32(void)
#define GLFW_KEY_F23
Definition: glfw3.h:453
#define GLFW_KEY_M
Definition: glfw3.h:390
#define GLFW_TRUE
One.
Definition: glfw3.h:279
#define GLFW_KEY_F4
Definition: glfw3.h:434
#define _glfwIsWindows10CreatorsUpdateOrGreaterWin32()
#define GLFW_KEY_RIGHT_BRACKET
Definition: glfw3.h:406
#define GLFW_KEY_LAST
Definition: glfw3.h:483
HRESULT(WINAPI * PFN_DwmIsCompositionEnabled)(BOOL *)
#define GLFW_KEY_DOWN
Definition: glfw3.h:420
#define GLFW_KEY_J
Definition: glfw3.h:387
static HWND createHelperWindow(void)
Definition: win32_init.c:332
void _glfwTerminateWGL(void)
Definition: wgl_context.c:463
#define GLFW_KEY_L
Definition: glfw3.h:389
#define SetProcessDpiAwareness
#define GLFW_KEY_KP_ENTER
Definition: glfw3.h:471
#define GLFW_KEY_KP_SUBTRACT
Definition: glfw3.h:469
#define GLFW_KEY_9
Definition: glfw3.h:375
#define GLFW_KEY_COMMA
Definition: glfw3.h:362
#define GLFW_KEY_RIGHT_ALT
Definition: glfw3.h:479
#define GLFW_KEY_F19
Definition: glfw3.h:449
#define GLFW_KEY_SLASH
Definition: glfw3.h:365
#define GLFW_KEY_PRINT_SCREEN
Definition: glfw3.h:429
#define GLFW_KEY_F22
Definition: glfw3.h:452
GLint GLsizei count
#define GLFW_KEY_LEFT_CONTROL
Definition: glfw3.h:474
DWORD(WINAPI * PFN_timeGetTime)(void)
#define GLFW_KEY_KP_8
Definition: glfw3.h:464
static const FGuid GUID
#define GLFW_KEY_Q
Definition: glfw3.h:394
#define GLFW_KEY_KP_0
Definition: glfw3.h:456
#define GLFW_KEY_KP_EQUAL
Definition: glfw3.h:472
GLsizei GLsizei GLchar * source
#define NULL
Definition: tinycthread.c:47
#define TRUE
Definition: tinycthread.c:50
int i
GLenum GLuint GLenum GLsizei length
#define GLFW_KEY_LEFT_ALT
Definition: glfw3.h:475
HRESULT(WINAPI * PFN_DirectInput8Create)(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN)
#define _GLFW_MESSAGE_SIZE
Definition: internal.h:59
#define GLFW_KEY_F3
Definition: glfw3.h:433
#define GLFW_KEY_F21
Definition: glfw3.h:451
#define GLFW_KEY_RIGHT_SHIFT
Definition: glfw3.h:477
#define GLFW_KEY_R
Definition: glfw3.h:395
#define GLFW_KEY_F16
Definition: glfw3.h:446
#define GLFW_KEY_RIGHT
Definition: glfw3.h:418
#define GLFW_KEY_Y
Definition: glfw3.h:402
#define GLFW_KEY_BACKSLASH
Definition: glfw3.h:405
#define GLFW_KEY_F18
Definition: glfw3.h:448
#define GLFW_KEY_O
Definition: glfw3.h:392
GLFWbool _glfwRegisterWindowClassWin32(void)
#define GLFW_KEY_APOSTROPHE
Definition: glfw3.h:361
#define GLFW_KEY_MINUS
Definition: glfw3.h:363
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
void _glfwUpdateKeyNamesWin32(void)
Definition: win32_init.c:461
#define GLFW_KEY_F24
Definition: glfw3.h:454
BOOL(WINAPI * PFN_SetProcessDPIAware)(void)
#define GLFW_KEY_5
Definition: glfw3.h:371
#define GLFW_KEY_LEFT_SUPER
Definition: glfw3.h:476
#define GLFW_KEY_C
Definition: glfw3.h:380
#define _GLFW_WNDCLASSNAME


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:23