HINSTANCE (how to get the instance of a program) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HINSTANCE (how to get the instance of a program)

minhtuanhtminhtuanht Posts: 1Member
How to get the HINSTANCE hInst.
I don't know any function that can help me do this.

Comments

  • LundinLundin Posts: 3,711Member
    : How to get the HINSTANCE hInst.
    : I don't know any function that can help me do this.
    :

    It is passed to main() at startup.
    It is passed to WM_CREATE in your windows message handling procedure.
    Besides that, you can get it with the function GetWindowLong().
  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2005-6-28 4:24:53[/red][/b][hr]
    : : How to get the HINSTANCE hInst.
    : : I don't know any function that can help me do this.
    : :
    :
    : It is passed to main() at startup.
    : It is passed to WM_CREATE in your windows message handling procedure.
    : Besides that, you can get it with the function GetWindowLong().
    :


    also, MSDN for WinMain() function (windows programs don't have main()), or if using MFC AfxGetInstanceHandle(). For console programs, call GetConsoleWindow() to get the HWND then GetWindowLong() to get the HINSTANCE.


  • MT2002MT2002 Posts: 1,444Member
    : [b][red]This message was edited by stober at 2005-6-28 4:24:53[/red][/b][hr]
    : : : How to get the HINSTANCE hInst.
    : : : I don't know any function that can help me do this.
    : : :
    : :
    : : It is passed to main() at startup.
    : : It is passed to WM_CREATE in your windows message handling procedure.
    : : Besides that, you can get it with the function GetWindowLong().
    : :
    :
    :
    : also, MSDN for WinMain() function (windows programs don't have main()), or if using MFC AfxGetInstanceHandle(). For console programs, call GetConsoleWindow() to get the HWND then GetWindowLong() to get the HINSTANCE.
    [blue]
    For the Win32 API, you could also use GetModuleHandle():[/blue]
    [code]
    [green]//get instance of current program (self)[/green]
    HINSTANCE hInst= GetModuleHandle (0);[/code]
Sign In or Register to comment.