I'm reading Schildt's Windows 98 Programming from the Ground Up, and this question is from pg 116 for anyone with a copy.
When calling DialogBox from within the window function, the handle to the current instance is required as a parameter. So Schildt declares a global HINSTANCE and sets it equal to the HINSTANCE passed to WinMain. I know that global variables should be avoided when possible, and I was wondering if there is a way around doing it like he does. (If it's covered later in the book, just tell me)
Code:
HINSTANCE hInst;
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs, int nWinMode)
{
...
hInst=hThisInst;
...
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
...
DialogBox(hInst, "MyDB, hwnd, (DLGPROC) DialogFunc);
...
}