Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Quick Question: HINSTANCE of Allegro

Credits go to CGamesPlay for helping out!
This thread is locked; no one can reply to it. rss feed Print
Quick Question: HINSTANCE of Allegro
Kris Asick
Member #1,424
July 2001

Under Windows, with Allegro, I know how to get the HWND property of the Allegro window, I know how to get the HDC property of Allegro bitmaps...

...but how do I get the HINSTANCE property of the application while using Allegro's magic main?

I know, it's probably a stupid question, but every so often they come up...

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

CGamesPlay
Member #2,559
July 2002
avatar

Google! "get hinstance from hwnd"

http://cboard.cprogramming.com/archive/index.php/t-60642.html

Quote:

Use GetModuleHandle() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getmodulehandle.asp) to get a handle to the process (GetModuleHandle() returns a HMODULE, but it's the same as HINSTANCE on 32 bit windows).

[append]

Another Google result says (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE), 0L);

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Kris Asick
Member #1,424
July 2001

I think the GetWindowLong() approach will work best, seeing as how in the future, HMODULE and HINSTANCE may not be the same thing.

Thanks! ;)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

DanielH
Member #934
January 2001
avatar

HWND hWnd           = NULL;
HWND hParent        = NULL;
HINSTANCE hInstance = NULL;

hWnd = win_get_window();
hInstance = (HINSTANCE)GetWindowLong( hWnd, GWL_HINSTANCE );
hParent = (HWND)GetWindowLong( hWnd, GWL_HWNDPARENT );

Kris Asick
Member #1,424
July 2001

Yep. Figured that out as I looked up GetWindowLong in the MSDN libraries.

I'm writing my own input handler to override the Allegro one, since I ran into a barricade trying to fix the one in Allegro under the Windows build without breaking Allegro in the process and couldn't do it. To access DirectInput though, I needed a handle to the application instance, which Allegro didn't have a built-in command for, but didn't want to switch from the magic main to WinMain.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Go to: