|
Prev: Get CPU Utilization without WMI
Next: Edit Control
From: daxxar on 7 May 2008 04:38 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; }
From: daxxar on 7 May 2008 07:28 On May 7, 10:38 am, daxxar <dax...(a)gmail.com> wrote: > 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.) I figured out what the problem was: This happen when the machine does not have comctl32.dll loaded, and you use one of these controls (stuff like tabs, hotkey-input-controls, etcetera). It has to be an API bug, though? In any case, adding a call to InitCommonControlsEx (with the right structure, see the API docs) solves this nicely. :)
|
Pages: 1 Prev: Get CPU Utilization without WMI Next: Edit Control |