Problem with DialogBox() returning -1
Hi!
I'm having problems where SOME of my users fail to run my program,
because DialogBox() returns -1. I've set up a MessageBox() that shows
the value of GetLastError(), and it returns 0 (The operation completed
successfully.)
Anyone have any suggestions as to what could cause this?
This is the relevant part of my code. (See http://pastebin.ca/1010305
for hilighted version)
BOOL CALLBACK ConfigProc(HWND hwnd, UINT Message, WPARAM wParam,
LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
{
HICON icon = LoadIcon(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_MYICON));
SendMessage(hwnd, WM_SETICON, (WPARAM)false, (LPARAM)icon);
loadConfig();
setConfig(hwnd);
ShowWindow(hwnd, SW_SHOW);
return TRUE;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
getConfig(hwnd);
if (!saveConfig())
{
/* TODO: Fix this */
}
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
}
case IDC_SAVE:
if (HIWORD(wParam) == BN_CLICKED)
{
getConfig(hwnd);
if (!saveConfig())
{
/* TODO: Fix this */
}
}
break;
default:
return FALSE;
}
return TRUE;
}
bool showConfigDialog(HINSTANCE instance)
{
int ret = DialogBox(instance, MAKEINTRESOURCE(IDD_CONFIG), NULL,
ConfigProc);
if (ret == IDOK)
return true;
else if (ret == -1)
{
char message[128];
sprintf(message, "Error when calling DialogBox(): %d (%d)",
GetLastError(), ret);
MessageBox(NULL, message, "Error", MB_OK | MB_ICONERROR);
}
return false;
}
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR
cmdLine, int showCmd)
{
if (showConfigDialog(instance))
return loadAndPatch(cmdLine);
else
return 0;
}