diff --git a/glutin/src/api/wgl/mod.rs b/glutin/src/api/wgl/mod.rs index ad83595eae..6a1d777a30 100644 --- a/glutin/src/api/wgl/mod.rs +++ b/glutin/src/api/wgl/mod.rs @@ -16,6 +16,7 @@ use winapi::shared::ntdef::LPCWSTR; use winapi::shared::windef::{HDC, HGLRC, HWND}; use winapi::um::libloaderapi::*; use winapi::um::wingdi::*; +use winapi::um::winnt::IMAGE_DOS_HEADER; use winapi::um::winuser::*; use std::ffi::{CStr, CString, OsStr}; @@ -772,7 +773,7 @@ unsafe fn load_extra_functions(win: HWND) -> Result Result Result { Ok(pf_id) } + +fn get_instance_handle() -> HINSTANCE { + // Gets the instance handle by taking the address of the + // pseudo-variable created by the Microsoft linker: + // https://devblogs.microsoft.com/oldnewthing/20041025-00/?p=37483 + + // This is preferred over GetModuleHandle(NULL) because it also works in DLLs: + // https://stackoverflow.com/questions/21718027/getmodulehandlenull-vs-hinstance + + extern "C" { + static __ImageBase: IMAGE_DOS_HEADER; + } + + unsafe { &__ImageBase as *const _ as _ } +}