Jump to content
  • Advertisement
Sign in to follow this  
dbzprogrammer

Win32 conflict

This topic is 4887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a question. I have created a window class that creates that will create a window's class, register it, create the window, setup pixel format, and handle messages. The problem is it needs the instance for the program, and I've designed this engine I'm working on to not have a main.cpp with the main function, so the developer using the engine could do that. So I need to get the hinstance to the calss, but how? I know I could make an extra parameter, but there's only one instance. Is that just the only option then?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by dbzprogrammer
I have a question. I have created a window class that creates that will create a window's class, register it, create the window


If you're creating the window, you have the HWND, correct?

HINSTANCE hinstance = (HINSTANCE)::GetWindowLong(hwnd, GWL_HINSTANCE);


HTH


Share this post


Link to post
Share on other sites
Quote:
Original post by dbzprogrammer
Oh.......so I can create a another HINSTANCE ans assign it GetModuleHandle(NULL)?

Or would i have to create it by doing the second one?


You can grab your programs HINSTANCE by doing either of those. If you have the HWND for the window, use the second one, otherwise use GetModuleHandle(NULL)

Share this post


Link to post
Share on other sites
Yes, or rather, you can get a copy of the handle that was supplied to WinMain by argument. It's not really a new instance, since GetModuleHandle does not increase the reference count of the module. In other words you don't have to do any housekeeping. You can discard the handle when you don't need it anymore without having to release/free it in any way.

Take a look at this example at MSDN. It shows how to create a simple dialog box that uses GDI brushes to draw a pattern. That part is not related to you but if you scroll down to the bottom of the page and look at the last piece of code you have:

DialogBox((HANDLE)GetModuleHandle(NULL), 
(LPTSTR)"CustBrush",
hWnd,
(DLGPROC) BrushDlgProc);

This is the general way to create a dialog box. The first parameter of DialogBox( ) takes the HINSTANCE of the executable where the dialog box resource is located, in this case the program executable itself; the one supplied by WinMain.

So, this is an example of how to use the GetModuleHandle( ) function. In your case you could do something like this:

HINSTANCE hAppInst;
hAppInst = (HANDLE)GetModuleHandle( NULL );

I hope this answers your question.

Good luck.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!