Nochmals Probleme mit modalem Dialog



  • Ich benutze die MSDN, um einen Modalen Dialog zu erstellen, doch die Scheisse strürzt jedes Mal mit einer massiven Speicherschutzverletzung ab... 😡
    Irgendwas habe ich offensichtlich falsch gemacht, doch mir will einfach nicht in den Schädel, was !!!
    Ich post mal den betreffenden Codeausschnitt:

    bool __stdcall Kyroforce2D::HardwareSettingsDlgProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam){
        switch(uMsg){
        default:
            return false;
        }
    }
    
    bool Kyroforce2D::getHardwareSettings(HWND hWnd){
        // create a handle to 1Kb window - memory and cast the memory to the needed pointers
        HGLOBAL hGbl = GlobalAlloc(GMEM_ZEROINIT,1024);
        DLGTEMPLATE *pDlg = (DLGTEMPLATE*)GlobalLock(hGbl);
        WORD *pTpl = (WORD*)pDlg+1;
    
        // create and init the dialog box
        pDlg->style = WS_POPUP|WS_BORDER|WS_SYSMENU|WS_CAPTION|DS_MODALFRAME;
        pDlg->cdit = 2;
        pDlg->x = pDlg->y = 50;
        pDlg->cx = pDlg->cy = 100;
    
        // init the dialog template
        *pTpl++ = 0;
        *pTpl++ = 0;
            pTpl +=  mbstowcs(pTpl,"Kyroforce2D Hardware Einstellungen",35)+1;
    
        // show the dialog box, free the allocated memory and return
        GlobalUnlock(hGbl);
        bool ret = !DialogBoxIndirectParam((HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),(DLGTEMPLATE*)hGbl,hWnd,(DLGPROC)&Kyroforce2D::HardwareSettingsDlgProc,(LPARAM)&this->hwInfo) ? true : false;
        GlobalFree(hGbl);
        return ret;
    }
    

    Ich hoffe, ihr findet was !!! 🙂
    Gruss Ishildur



  • kA, aber ich finde

    // init the dialog template
    *pTpl++ = 0;
    *pTpl++ = 0;
    pTpl +=  mbstowcs(pTpl,"Kyroforce2D Hardware Einstellungen",35)+1;
    

    sieht etwas komisch aus (zumindest anders als in diesem FAQ Beitrag) -> mach's doch mal so wie dort 😉



  • Das hatte ich schon getan, funktionierte allerdings leider auch nicht. Allerdings denke ich doch, dass dies nur eine verkürzte Schreibweise von dem FAQ Beitrag ist ??

    Gruss Ishildur



  • Warum nicht per Resource-Editor?



  • Naja, es ist erst zur Laufzeit bekannt, wie der Dialog aussehen wird...



  • Also wenn das Beispiel aus den FAQ bei dir schon nicht funktioniert kann ich dir leider auch nicht weiterhelfen 😞


Anmelden zum Antworten