diff options
author | James Ross-Gowan <rossymiles@gmail.com> | 2016-06-10 22:37:29 +1000 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-06-11 15:35:17 +0200 |
commit | 9fcc517cee13ad446ddbf40cd63c013d50fd14d0 (patch) | |
tree | 5b2724f93193b1c07937d1d2a210fbba7c816361 /video/out/opengl | |
parent | de4c74e5a4a996e8ff431c8f33a32c4b580be203 (diff) | |
download | mpv-9fcc517cee13ad446ddbf40cd63c013d50fd14d0.tar.bz2 mpv-9fcc517cee13ad446ddbf40cd63c013d50fd14d0.tar.xz |
win32: use HINST_THISCOMPONENT
This is a common idiom used in MSDN docs and Raymond Chen's example
programs to get a HINSTANCE for the current module, regardless of
whether it's an .exe or a .dll. Using GetModuleHandle(NULL) for this is
technically incorrect, since it always gets a handle to the .exe, even
when the executing code (in libmpv) is running in a .dll. In this case,
using the wrong HINSTANCE could cause namespace issues with window
classes, since CreateWindowEx uses the HINSTANCE to search for the
matching window class name.
See:
https://blogs.msdn.microsoft.com/oldnewthing/20050418-59/?p=35873
https://blogs.msdn.microsoft.com/oldnewthing/20041025-00/?p=37483
Diffstat (limited to 'video/out/opengl')
-rw-r--r-- | video/out/opengl/context_dxinterop.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/video/out/opengl/context_dxinterop.c b/video/out/opengl/context_dxinterop.c index 4dfc3c2108..a4dc165132 100644 --- a/video/out/opengl/context_dxinterop.c +++ b/video/out/opengl/context_dxinterop.c @@ -27,6 +27,9 @@ // For WGL_ACCESS_WRITE_DISCARD_NV, etc. #include <GL/wglext.h> +EXTERN_C IMAGE_DOS_HEADER __ImageBase; +#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase) + // mingw-w64 header typo? #ifndef IDirect3DSwapChain9Ex_GetBackBuffer #define IDirect3DSwapChain9Ex_GetBackBuffer IDirect3DSwapChain9EX_GetBackBuffer @@ -99,7 +102,7 @@ static int os_ctx_create(struct MPGLContext *ctx) .cbSize = sizeof(WNDCLASSEXW), .style = CS_OWNDC, .lpfnWndProc = DefWindowProc, - .hInstance = GetModuleHandleW(NULL), + .hInstance = HINST_THISCOMPONENT, .lpszClassName = os_wnd_class, }); @@ -107,7 +110,7 @@ static int os_ctx_create(struct MPGLContext *ctx) // possible to use the VO window, but MSDN recommends against drawing to // the same window with flip mode present and other APIs, so play it safe. p->os_wnd = CreateWindowExW(0, os_wnd_class, os_wnd_class, 0, 0, 0, 200, - 200, NULL, NULL, GetModuleHandleW(NULL), NULL); + 200, NULL, NULL, HINST_THISCOMPONENT, NULL); p->os_dc = GetDC(p->os_wnd); if (!p->os_dc) { MP_FATAL(ctx->vo, "Couldn't create window for offscreen rendering\n"); |