Jump to content

  • Log In with Google      Sign In   
  • Create Account


Win32: Creating a new HINSTANCE ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Darragh   Members   -  Reputation: 305

Like
0Likes
Like

Posted 15 February 2006 - 02:19 AM

Hi everyone. I'm currently in the process of creating a simplified little Win32 / OpenGL wrapper for use in our maths class, so we can all mess about with transforms and matrices etc. quickly and easily. What I want to do is make a simple class which allows the user to display some common primitives, modify the transformation matrices and other such things and handle all of the details behind Windows programming. I want to hide away as much as possible, all of the Win32 details especially the standard WinMain function. Presently the main part of program uses the standard Win32 template- and passes the hInstance paramter to the constructor for my OpenGL Window class, which it then uses when creating the window. The code for this looks something like below:

#include <windows.h>
#include "GL_Window.h"

int WinMain
(          
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPSTR     lpCmdLine,
  int        nCmdShow
);
{
   // Create a new OpenGL Window which allows drawing etc.. 

   GL_Window pWindow = new GL_Window( hInstance ); return 0;

}

What I'd prefer to do is replace WinMain with the standard main() function and have the window create its own process and handle in its constructor:
#include "GL_Window.h"

int main ( void );
{
   // Create a new OpenGL Window which allows drawing etc..

   GL_Window pWindow = new GL_Window(); return 0;
}

Is such a thing possible to do ? Or can only Windows itself create a new program space and pass the handle through WinMain ? It would be ideal if the GL_Window class could manage its own details completely without reliance on the main() function for paramters. If anyone has any ideas or good links then i would be grateful. I've been looking through MSDN but haven't found anything to point me in the right direction, then again maybe i've been looking in the wrong places. Cheers, Darragh

Sponsor:

#2 Catafriggm   Members   -  Reputation: 296

Like
0Likes
Like

Posted 15 February 2006 - 02:26 AM

Mu.

Windows creates your process for you. Where would your executable run if not in its own process? You can't run two executables in the same process.

#3 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
0Likes
Like

Posted 15 February 2006 - 02:30 AM

HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);

#4 Endurion   Crossbones+   -  Reputation: 3464

Like
0Likes
Like

Posted 15 February 2006 - 02:31 AM

You can get all those parameters from the WinMain with WinAPI functions.

GetModuleHandle( NULL ) returns your HINSTANCE
GetCommandLine returns the passed parameters (appended in one string, so you have to seperate them yourself)
GetStartupInfo fills a struct that holds in wShowWindow the nCmdShow param

The previous instance handle is always NULL for 32bit-apps.

Edit: Bad Oluseyi, stop being that fast :)

#5 Darragh   Members   -  Reputation: 305

Like
0Likes
Like

Posted 15 February 2006 - 02:33 AM

Quote:
Original post by Catafriggm
Mu.

Windows creates your process for you. Where would your executable run if not in its own process? You can't run two executables in the same process.


I understand that much. I thought it was possible to create your own though ? - maybe i'm a bit confused here. Is HINSTANCE a handle to a program or just an individual process ?

Is there another way to get the HINSTANCE variable i need from within the GL_Window constructor without relying on main() ? The aim is simply to make the GL_Window class as independant as possible. It shouldn't (ideally) need a handle obtained from main in order to create its window.



#6 Darragh   Members   -  Reputation: 305

Like
0Likes
Like

Posted 15 February 2006 - 02:33 AM

Quote:
Original post by Oluseyi
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);


Wow, that was quick!

Thank you. That is exactly what i was looking for! : )

#7 SiCrane   Moderators   -  Reputation: 9565

Like
0Likes
Like

Posted 15 February 2006 - 02:34 AM

Also, if you're programming only for the NT based kernels (NT, Win2K and XP) then the HINSTANCE parameter to CreateWindow() is ignored, which means you don't need it to create a window.

#8 Darragh   Members   -  Reputation: 305

Like
0Likes
Like

Posted 15 February 2006 - 02:36 AM

Quote:
Original post by SiCrane
Also, if you're programming only for the NT based kernels (NT, Win2K and XP) then the HINSTANCE parameter to CreateWindow() is ignored, which means you don't need it to create a window.


Cool. Thats even easier still. Thanks everyone, I can go ahead now and get my little window up and running..





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS