Thread: Getting hInst without WinMain

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    75

    Getting hInst without WinMain

    Is it possible to get the hInst variable without getting it from the WinMain function. I mean is there a function I can call to just get the instance handle?

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    #include <windows.h>

    hInst = GetModuleHandle(NULL);
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    75

    thx

    Gottcha. Thx.

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Hmm...to do this I use

    hInst = GetWindowLong(hwnd, GWL_HINSTANCE);

    I'm not sure if this syntax is totally correct, but it's the idea.

    Look up this function. I know you don't want to do this in WinMain, but you can create a global HINSTANCE and just define it to be the first param of WinMain if you like. Then, it can be accessed anywhere.

    Garfield
    1978 Silver Anniversary Corvette

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    >> but you can create a global HINSTANCE and just define it to be the first param of WinMain

    This seems to be a pretty common practice, espically among the code samples from microsoft. Isn't that supposed to be some sort of deadly sin in programming (as in using a global variable)?

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by shtarker
    >> Isn't that supposed to be some sort of deadly sin in programming (as in using a global variable)?
    Depends on the program......if it is a game then it is better to have global variable than to pass them to each function as it is much faster.....

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, if you have like 30 global variables declared. It is just an organization thing, as far as I'm concerned, and it's easier to do that with a globa HINSTANCE.
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WinMain entry point in .lib
    By cloudy in forum Windows Programming
    Replies: 8
    Last Post: 10-28-2006, 12:16 PM
  2. WinMain Paramaters.
    By C+noob in forum Windows Programming
    Replies: 8
    Last Post: 07-11-2005, 11:44 AM
  3. Silly WinMain question
    By Magos in forum Windows Programming
    Replies: 2
    Last Post: 09-07-2002, 09:38 AM
  4. Is this necessary: int APIENTRY WinMain
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 06-26-2002, 07:09 PM
  5. WinMain() just after message loop...
    By Hunter2 in forum Windows Programming
    Replies: 12
    Last Post: 06-06-2002, 08:36 PM