mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-26 12:18:51 -05:00
Win32: Fix using executable instance and not ours
Operations that take an instance handle should be passed the handle of whatever module we are inside instead of blindly passing the handle of the executable. This commit makes GLFW retrieve its own instance on initialization. This makes the most difference for window classes, which are per-instance. Using the executable instance led to name conflicts if there were several copies of GLFW in a single process. Note that having this is still a bad idea unless you know what things to avoid, and those things are mostly platform-specific. This is partly because the library wasn't designed for it and partly because it needs to save, update and restore various per-process and per-session settings like current context and video mode. However, multiple simultaneous copies of GLFW in a single Win32 process should now at least initialize, like is already the case on other platforms. Fixes #469 Fixes #1296 Fixes #1395 Related to #927 Related to #1885
This commit is contained in:
parent
66a4882eb1
commit
07a5518c3e
|
@ -90,6 +90,7 @@ video tutorials.
|
|||
- IntellectualKitty
|
||||
- Aaron Jacobs
|
||||
- Erik S. V. Jansson
|
||||
- jjYBdx4IL
|
||||
- Toni Jovanoski
|
||||
- Arseny Kapoulkine
|
||||
- Cem Karan
|
||||
|
@ -210,6 +211,7 @@ video tutorials.
|
|||
- Jared Tiala
|
||||
- Sergey Tikhomirov
|
||||
- Arthur Tombs
|
||||
- TronicLabs
|
||||
- Ioannis Tsakpinis
|
||||
- Samuli Tuomola
|
||||
- Matthew Turner
|
||||
|
|
|
@ -214,6 +214,7 @@ information on what to include when reporting a bug.
|
|||
scancode than `PrtSc` (#1993)
|
||||
- [Win32] Bugfix: `GLFW_KEY_PAUSE` scancode from `glfwGetKeyScancode` did not
|
||||
match event scancode (#1993)
|
||||
- [Win32] Bugfix: Instance-local operations used executable instance (#469,#1296,#1395)
|
||||
- [Cocoa] Added support for `VK_EXT_metal_surface` (#1619)
|
||||
- [Cocoa] Added locating the Vulkan loader at runtime in an application bundle
|
||||
- [Cocoa] Moved main menu creation to GLFW initialization time (#1649)
|
||||
|
|
|
@ -71,6 +71,16 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
|||
//
|
||||
static GLFWbool loadLibraries(void)
|
||||
{
|
||||
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
||||
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
(const WCHAR*) &_glfw,
|
||||
(HMODULE*) &_glfw.win32.instance))
|
||||
{
|
||||
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
||||
"Win32: Failed to retrieve own module handle");
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
_glfw.win32.user32.instance = _glfwPlatformLoadModule("user32.dll");
|
||||
if (!_glfw.win32.user32.instance)
|
||||
{
|
||||
|
@ -334,7 +344,7 @@ static GLFWbool createHelperWindow(void)
|
|||
WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
|
||||
0, 0, 1, 1,
|
||||
NULL, NULL,
|
||||
GetModuleHandleW(NULL),
|
||||
_glfw.win32.instance,
|
||||
NULL);
|
||||
|
||||
if (!_glfw.win32.helperWindowHandle)
|
||||
|
|
|
@ -574,7 +574,7 @@ GLFWbool _glfwInitJoysticksWin32(void)
|
|||
{
|
||||
if (_glfw.win32.dinput8.instance)
|
||||
{
|
||||
if (FAILED(DirectInput8Create(GetModuleHandleW(NULL),
|
||||
if (FAILED(DirectInput8Create(_glfw.win32.instance,
|
||||
DIRECTINPUT_VERSION,
|
||||
&IID_IDirectInput8W,
|
||||
(void**) &_glfw.win32.dinput8.api,
|
||||
|
|
|
@ -442,6 +442,7 @@ typedef struct _GLFWwindowWin32
|
|||
//
|
||||
typedef struct _GLFWlibraryWin32
|
||||
{
|
||||
HINSTANCE instance;
|
||||
HWND helperWindowHandle;
|
||||
HDEVNOTIFY deviceNotificationHandle;
|
||||
int acquiredMonitorCount;
|
||||
|
|
|
@ -1321,7 +1321,7 @@ static int createNativeWindow(_GLFWwindow* window,
|
|||
fullWidth, fullHeight,
|
||||
NULL, // No parent window
|
||||
NULL, // No window menu
|
||||
GetModuleHandleW(NULL),
|
||||
_glfw.win32.instance,
|
||||
(LPVOID) wndconfig);
|
||||
|
||||
_glfw_free(wideTitle);
|
||||
|
@ -1429,7 +1429,7 @@ GLFWbool _glfwRegisterWindowClassWin32(void)
|
|||
wc.cbSize = sizeof(wc);
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
||||
wc.lpfnWndProc = (WNDPROC) windowProc;
|
||||
wc.hInstance = GetModuleHandleW(NULL);
|
||||
wc.hInstance = _glfw.win32.instance;
|
||||
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
|
||||
wc.lpszClassName = _GLFW_WNDCLASSNAME;
|
||||
|
||||
|
@ -1459,7 +1459,7 @@ GLFWbool _glfwRegisterWindowClassWin32(void)
|
|||
//
|
||||
void _glfwUnregisterWindowClassWin32(void)
|
||||
{
|
||||
UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL));
|
||||
UnregisterClassW(_GLFW_WNDCLASSNAME, _glfw.win32.instance);
|
||||
}
|
||||
|
||||
int _glfwCreateWindowWin32(_GLFWwindow* window,
|
||||
|
@ -2447,7 +2447,7 @@ VkResult _glfwCreateWindowSurfaceWin32(VkInstance instance,
|
|||
|
||||
memset(&sci, 0, sizeof(sci));
|
||||
sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||
sci.hinstance = GetModuleHandleW(NULL);
|
||||
sci.hinstance = _glfw.win32.instance;
|
||||
sci.hwnd = window->win32.handle;
|
||||
|
||||
err = vkCreateWin32SurfaceKHR(instance, &sci, allocator, surface);
|
||||
|
|
Loading…
Reference in New Issue
Block a user