In Win32 programming, an HINSTANCE is a #define'd handle type which basically (conceptually) means a handle to your current executable module. You receive it from WinMain when you launch an app, and you use it in such functions as LoadResource, LoadString, and CreateDialog, so that the program knows where to load the resource ID from.

You can easily get the hInstance for your app if you have a window created from that module by using GetWindowLong. Inside each hWnd's long data, the hInstance is stored there for easy use:
       HINSTANCE myhInst = (HISNTANCE) GetWindowLong(myHwnd, GWL_HINSTANCE);

It's a common trick. You'll need to cast it over from type LONG (psst, it's secretly the same size). Because of security, you can only mess with hInstance's that you own, or that are ancestors of your process (or of library that you load), although you can interact with other ones (ie: send their windows messages).

Log in or register to write something here or to contact authors.