Original Post
Hi all!
First of all: I'm a bit tired right now, so maybe I just missed something in my code.
I wrote a little wrapper for win32 dialogs that gives me the ability to put the MsgProc into my class instead of having a global function.
Unfortunately it crashes when I want to access my object, with an unhandled exception.
Here is the code:
How can that be? I did this several times before, and this code was mostly copied out from my other files.
First of all: I'm a bit tired right now, so maybe I just missed something in my code.
I wrote a little wrapper for win32 dialogs that gives me the ability to put the MsgProc into my class instead of having a global function.
Unfortunately it crashes when I want to access my object, with an unhandled exception.
Here is the code:
/** This function creates the dialog window */HWND wtechDialog::CreateDialogWindow(HINSTANCE hInstance, LPWSTR Dialog){ // Create the window with this object as param DialogWindow = CreateDialogParam(hInstance, Dialog, NULL, (DLGPROC)StaticWndProc, (LPARAM) this); hInst=hInstance; return DialogWindow;}/** You can use this message to process the messages */LRESULT wtechDialog::WndProc(HWND hDlg, int Msg, WPARAM wParam, LPARAM lParam){ return 0;}/** This is used internally */LRESULT wtechDialog::StaticWndProc(HWND hDlg, int Msg, WPARAM wParam, LPARAM lParam){ if (Msg == WM_INITDIALOG) { LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; wtechDialog *Dialog = (wtechDialog *)pcs->lpCreateParams; ::SetWindowLongPtrW( hDlg, GWLP_USERDATA, PtrToUlong(Dialog) ); //Call the user msg proc return Dialog->WndProc(hDlg, Msg, wParam, lParam); //<------ Crashes here! } else { wtechDialog *Dialog = reinterpret_cast<wtechDialog *>(static_cast<LONG_PTR>( ::GetWindowLongPtrW( hDlg, GWLP_USERDATA ))); if(Dialog) { //Call the user msg proc return Dialog->WndProc(hDlg, Msg, wParam, lParam); //<----- If I comment the above out, it crashes here! } }}How can that be? I did this several times before, and this code was mostly copied out from my other files.