Main.cpp
main.hCode:#include <windows.h> #include "Resource.h" #include "utils.h" #include "main.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { CDlg *pDlg = new CDlg(hInstance); pDlg->SetTemplate(MAKEINTRESOURCE(IDD_DIALOG1)); if (!pDlg->AllocDlg()) { MessageBox(0, "No dlg", "Error", 16); } pDlg->FreeDlg(); delete pDlg; return 0; }
My executable crashes...any ideas?Code:class CDlg { public: CDlg(HINSTANCE hInstance) : g_hInstance(hInstance){} ~CDlg() { delete[] pTemplate; } void SetTemplate(const char *lpTemplate) { int iSize = _lstrlen(lpTemplate); pTemplate = new char[iSize+1]; _lstrcpy(pTemplate, lpTemplate); } bool AllocDlg() { hDlg = CreateDialog(g_hInstance, pTemplate, 0, DLGPROC(DlgProc)); return (hDlg ? true : false); } void FreeDlg() { if (hDlg) DestroyWindow(hDlg); } static LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam) { MessageBox(NULL, NULL, "Call 1", 0); CDlg *Obj = reinterpret_cast<CDlg*>(GetWindowLong(hwnd, GWL_USERDATA)); if (Obj) { switch(Msg) { case WM_INITDIALOG: { SetWindowLong(hwnd, GWL_USERDATA, (LONG)Obj); return Obj->DlgProc(hwnd, Msg, wParam, lParam); } case WM_CLOSE: { DestroyWindow(hwnd); return Obj->DlgProc(hwnd, Msg, wParam, lParam); } case WM_DESTROY: { PostQuitMessage(0); return Obj->DlgProc(hwnd, Msg, wParam, lParam); } } return Obj->DlgProc(hwnd, Msg, wParam, lParam); } else { return Obj->DlgProc(hwnd, Msg, wParam, lParam); } } protected: private: HINSTANCE g_hInstance; char *pTemplate; HWND hDlg; };



LinkBack URL
About LinkBacks



