Do yourself a favor. Take this function and place it in your include files. Call it once in WinMain and forget about it. After being initialized, call this function without parameters whenever you need a handle to the current instance!
I got so tired of passing this useless variable around and I haven't missed it since!
ie:
int WINAPI WinMain(HINSTANCE hThisInstance, //...)
{
Instance( hThisInstance ); //...initialize once...
//...stuff
}
HBITMAP GetBitmap(char *name)
{
return LoadBitmap( Instance(), name ); //...get this instance...
}
Code:
HINSTANCE Instance( HINSTANCE hThisInstance = NULL )
{
static HINSTANCE globalInstance;
if(hThisInstance != NULL) globalInstance = hThisInstance;
return globalInstance;
}
//...or try the AI version:
HINSTANCE Instance( HINSTANCE hThisInstance = NULL )
{
static bool forgot = true;
static HINSTANCE globalInstance;
if(hThisInstance != NULL)
{
globalInstance = hThisInstance;
forgot = false;
}
if(forgot) MessageBox(NULL, "You Forgot To Call Me In WinMain ;)", "Hey, Mr. Programmer:", 0);
return globalInstance;
}