What's an "Instance"...?

This is a discussion on What's an "Instance"...? within the Windows Programming forums, part of the Platform Specific Boards category; I can't seem to understand exactly what an "Instance" is. You know, like: HINSTANCE hInstance or HINSTNACE hPrevInstance. I've been ...

  1. #1
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291

    What's an "Instance"...?

    I can't seem to understand exactly what an "Instance" is.
    You know, like: HINSTANCE hInstance or HINSTNACE hPrevInstance.

    I've been passing hInstance (the WinMain parameter) to all
    the functions that have a HINSTANCE parameter, but I'm not
    exactly sure what a HINSTNACE is.

    When would be an example of a time where you'd pass another
    HINSTANCE to a function (not WinMain's hInstance)? When would
    you create another HINSTANCE variable?
    Staying away from General.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Hi ethic, hope you are well

    HINSTANCE is the starting/base address of your application as passed to your windows program by WinMain and is itself obtained for passing to WinMain by GetModuleHandle(0) - you can use this fn at any time in the lifetime of your app to get your application's HINSTANCE (HMODULE, the return type of GetModuleHandle is the same thing). WinMain's hPrevInstance is an obsolete term for 16bit backward compatibility; for all practical purposes just ignore it.

    You would create or get an instance handle when you wanted to map a dll into your application's address space with eg. LoadLibrary("name of dll"). The HINSTANCE in this case would be the base address for your dll (within your app's address space?)

    There may be other scenarios but I think that covers the basics. Fordy, Adrianxw and Novacain will probably be able to give you a more detailed and explicit answer but I hope that has helped some.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21