We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3486 - Can't get HINSTANCE of my window
Summary: Can't get HINSTANCE of my window
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.1
Hardware: x86_64 Windows (All)
: P2 blocker
Assignee: realitix
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-10 18:12 UTC by realitix
Modified: 2016-11-21 05:19 UTC (History)
2 users (show)

See Also:


Attachments
First revision of the patch (1.56 KB, patch)
2016-11-16 14:54 UTC, realitix
Details | Diff
Rev2 (1.87 KB, patch)
2016-11-16 15:08 UTC, realitix
Details | Diff
Patch set 3 - Compiled, Tested, Working (2.15 KB, patch)
2016-11-18 16:22 UTC, realitix
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description realitix 2016-11-10 18:12:01 UTC
SDL2 allows to create widow and to get information through SDL_SysWMinfo.
But it misses something, with Vulkan, you need the HWND and HINSTANCE of the window for Win32 system.
Sadly, SDL2 provides only HWND but not HINSTANCE.

I could make a pull request but I'm not comfortable with Mercurial.
Can you add it ?

Thanks,
Jean-Sébastien
Comment 1 Sam Lantinga 2016-11-11 20:43:47 UTC
You should be able to use GetModuleHandle(NULL) for the hinstance. Please reopen this bug if that doesn't work for you.
Comment 2 realitix 2016-11-13 10:42:41 UTC
Hi Sam Lantinga, indeed I could use GetModuleHandle but that would require to use the Windows library.
SDL2 is cross plateform and maybe should be in charge of this kind of things. Moreover, you could say "why this property and not another one..", because Vulkan needs it so the HINSTANCE property becomes a lot more important to get.

In some context, it can be difficult to get the HINSTANCE, indeed, I'm using pySDL2 (Python) and I can only access properties that SDL2 gives me.
I have to use a dirty trick like that to get the HINSTANCE:  (https://raw.githubusercontent.com/bglgwyng/pyVulkan/master/examples/win32misc.py)

I could add: why SDL2 provides HDC and not HINSTANCE ?

Thanks,
Jean-Sébastien
Comment 3 Sam Lantinga 2016-11-14 06:54:33 UTC
It totally could, I'll add that to my TODO list.

Also I'm going to see if we can add some cross-platform Vulkan support so you don't have to do those tricks.
Comment 4 realitix 2016-11-15 16:04:22 UTC
I'm doing it. It will help me to understand SDL2 code.
Sam Lantigua, can you tell me the procedure to make a pull request ?
Comment 5 realitix 2016-11-16 14:54:50 UTC
Created attachment 2633 [details]
First revision of the patch

Here my first patch,
please review it and let me know what you think about it.
Comment 6 realitix 2016-11-16 15:08:45 UTC
Created attachment 2634 [details]
Rev2
Comment 7 Ozkan Sezer 2016-11-17 11:16:53 UTC
(In reply to realitix from comment #6)
> Created attachment 2634 [details]
> Rev2

This will fail to build for _WIN64.  GetWindowLong() needs replacing to
GetWindowLongPtr(), and GWL_HINSTANCE needs replacing to GWLP_HINSTANCE.
Comment 8 realitix 2016-11-18 07:15:30 UTC
Thanks for your feedback, I'm working on it
Comment 9 realitix 2016-11-18 16:22:19 UTC
Created attachment 2636 [details]
Patch set 3 - Compiled, Tested, Working

This patch works great.

It works on 32 and 64 bits Windows.
Comment 10 Sam Lantinga 2016-11-21 05:19:21 UTC
Implemented, thanks!
https://hg.libsdl.org/SDL/rev/fbd8834ba7b8