Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CDialog DoModal function [Moved]

CDialog DoModal function [Moved]

Scheduled Pinned Locked Moved C / C++ / MFC
20 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P prithaa

    thanks I will check with that. But not working means I am getting Debug Assertion failure for DoModal() function. Can u please clear Are you sure that all your dialog items are correctly aligned to WORD or DWORD boundaries, as required? Pritha

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #10

    prithaa wrote:

    I am getting Debug Assertion failure for DoModal() function.

    Well that should give you a clue; look at the details of the assertion and try to figure out why it is getting thrown, and which parameter in your dialog may be causing the problem.

    prithaa wrote:

    Can u please clear ...

    I mean, check the positioning of all your dialog items in memory to ensure that they are correctly aligned, before you call DoModal(); for further information see here[^].

    Just say 'NO' to evaluated arguments for diadic functions! Ash

    P 1 Reply Last reply
    0
    • L Lost User

      prithaa wrote:

      I am getting Debug Assertion failure for DoModal() function.

      Well that should give you a clue; look at the details of the assertion and try to figure out why it is getting thrown, and which parameter in your dialog may be causing the problem.

      prithaa wrote:

      Can u please clear ...

      I mean, check the positioning of all your dialog items in memory to ensure that they are correctly aligned, before you call DoModal(); for further information see here[^].

      Just say 'NO' to evaluated arguments for diadic functions! Ash

      P Offline
      P Offline
      prithaa
      wrote on last edited by
      #11

      thanks

      L 1 Reply Last reply
      0
      • P prithaa

        thanks

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #12

        So does this solve the problem?

        Just say 'NO' to evaluated arguments for diadic functions! Ash

        P 1 Reply Last reply
        0
        • L Lost User

          So does this solve the problem?

          Just say 'NO' to evaluated arguments for diadic functions! Ash

          P Offline
          P Offline
          prithaa
          wrote on last edited by
          #13

          No but then I got a few guidelines towards the solutions. can i paste my code hear .It is about memory allocation and then calling InitModalIndirect Pritha

          L 1 Reply Last reply
          0
          • P prithaa

            No but then I got a few guidelines towards the solutions. can i paste my code hear .It is about memory allocation and then calling InitModalIndirect Pritha

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #14

            prithaa wrote:

            can i paste my code hear

            Sure, if you think it will be useful for others.

            Just say 'NO' to evaluated arguments for diadic functions! Ash

            P 1 Reply Last reply
            0
            • L Lost User

              prithaa wrote:

              can i paste my code hear

              Sure, if you think it will be useful for others.

              Just say 'NO' to evaluated arguments for diadic functions! Ash

              P Offline
              P Offline
              prithaa
              wrote on last edited by
              #15

              int MFC::Dialog::DoModal() { int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0); int szBoxLen = cWC + 1; WCHAR *szBoxCaption = new WCHAR[szBoxLen]; // Copy the string... MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, (LPWSTR) szBoxCaption, cWC); szBoxCaption[cWC] = 0; szBoxLen = (cWC) * sizeof(WCHAR); int nBufferSize = sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) /*menu and class + szBoxLen /*size of caption*/ + sizeof(WORD) /*fontsize*/ ;//+ nFontNameLen /*size of fontname*/; HLOCAL hLocal = LocalAlloc(LHND, nBufferSize); if (hLocal != NULL) { BYTE* pBuffer = (BYTE*)LocalLock(hLocal); if (pBuffer == NULL) { LocalFree(hLocal); AfxMessageBox(_T("D::DoModal() : LocalLock Failed")); } BYTE *pdest = pBuffer; // transfer DLGTEMPLATE structure to the buffer memcpy(pdest, &m_DialogTemplate, sizeof(DLGTEMPLATE)); // DLGTemplate pdest += sizeof(DLGTEMPLATE); *(WORD*)pdest = 0;// no menu -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment *(WORD*)(pdest + 1) = 0; // use default window class -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment memcpy(pdest, szBoxCaption, szBoxLen); // Caption pdest += szBoxLen; //These are the MFC functions, which do the job... InitModalIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd); int iRet =0; iRet = CDialog::DoModal(); LocalUnlock(hLocal); LocalFree(hLocal); return 0; } else { AfxMessageBox(_T("D::DoModal() : LocalAllock Failed")); return -1; } }

              L 1 Reply Last reply
              0
              • P prithaa

                int MFC::Dialog::DoModal() { int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0); int szBoxLen = cWC + 1; WCHAR *szBoxCaption = new WCHAR[szBoxLen]; // Copy the string... MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, (LPWSTR) szBoxCaption, cWC); szBoxCaption[cWC] = 0; szBoxLen = (cWC) * sizeof(WCHAR); int nBufferSize = sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) /*menu and class + szBoxLen /*size of caption*/ + sizeof(WORD) /*fontsize*/ ;//+ nFontNameLen /*size of fontname*/; HLOCAL hLocal = LocalAlloc(LHND, nBufferSize); if (hLocal != NULL) { BYTE* pBuffer = (BYTE*)LocalLock(hLocal); if (pBuffer == NULL) { LocalFree(hLocal); AfxMessageBox(_T("D::DoModal() : LocalLock Failed")); } BYTE *pdest = pBuffer; // transfer DLGTEMPLATE structure to the buffer memcpy(pdest, &m_DialogTemplate, sizeof(DLGTEMPLATE)); // DLGTemplate pdest += sizeof(DLGTEMPLATE); *(WORD*)pdest = 0;// no menu -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment *(WORD*)(pdest + 1) = 0; // use default window class -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment memcpy(pdest, szBoxCaption, szBoxLen); // Caption pdest += szBoxLen; //These are the MFC functions, which do the job... InitModalIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd); int iRet =0; iRet = CDialog::DoModal(); LocalUnlock(hLocal); LocalFree(hLocal); return 0; } else { AfxMessageBox(_T("D::DoModal() : LocalAllock Failed")); return -1; } }

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #16

                Please could you put <pre></pre> tags around your code so that it is readable (just edit your message and use the code block button). Also use the Preview button before you post to make sure it is all formatted correctly. Your code looks like: int MFC::Dialog::DoModal() { int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0); int szBoxLen = cWC + 1; WCHAR *szBoxCaption = new WCHAR[szBoxLen]; // ... it should look like:

                int MFC::Dialog::DoModal()
                {
                int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0);
                int szBoxLen = cWC + 1;
                WCHAR *szBoxCaption = new WCHAR[szBoxLen];
                // ...

                Just say 'NO' to evaluated arguments for diadic functions! Ash

                P 1 Reply Last reply
                0
                • L Lost User

                  Please could you put <pre></pre> tags around your code so that it is readable (just edit your message and use the code block button). Also use the Preview button before you post to make sure it is all formatted correctly. Your code looks like: int MFC::Dialog::DoModal() { int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0); int szBoxLen = cWC + 1; WCHAR *szBoxCaption = new WCHAR[szBoxLen]; // ... it should look like:

                  int MFC::Dialog::DoModal()
                  {
                  int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0);
                  int szBoxLen = cWC + 1;
                  WCHAR *szBoxCaption = new WCHAR[szBoxLen];
                  // ...

                  Just say 'NO' to evaluated arguments for diadic functions! Ash

                  P Offline
                  P Offline
                  prithaa
                  wrote on last edited by
                  #17

                  DLGTEMPLATE m_DialogTemplate;

                  int MFC::Dialog::DoModal() { //For OK and Cancel buttons?? m_DialogTemplate.cy+=(DlgControls.size()*4); AddOkCancel(); int iRet=0; //presetting for caption in the dialog.... int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL,0); int szBoxLen = cWC + 1; WCHAR *szBoxCaption = new WCHAR[szBoxLen]; // Copy the string... MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, (LPWSTR)szBoxCaption, cWC); szBoxCaption[cWC] = 0; szBoxLen = (cWC) * sizeof(WCHAR); int nBufferSize = sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) /*menu and class*/ + szBoxLen /*size of caption*/ + sizeof(WORD) /*fontsize*/ ;//+ nFontNameLen /*size of fontname*/; HLOCAL hLocal = LocalAlloc(LHND, nBufferSize); if (hLocal != NULL) { BYTE* pBuffer = (BYTE*)LocalLock(hLocal); if (pBuffer == NULL) { LocalFree(hLocal); AfxMessageBox(_T("D::DoModal() : LocalLock Failed")); } BYTE *pdest = pBuffer; // transfer DLGTEMPLATE structure to the buffer memcpy(pdest, &m_DialogTemplate, sizeof(DLGTEMPLATE)); // DLGTemplate pdest += sizeof(DLGTEMPLATE); *(WORD*)pdest = 0; // no menu -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment *(WORD*)(pdest + 1) = 0; // use default window class -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment memcpy(pdest, szBoxCaption, szBoxLen); // Caption pdest += szBoxLen; //These are the MFC functions, which do the job... InitModalIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd); iRet = CDialog::DoModal(); LocalUnlock(hLocal); LocalFree(hLocal); return iRet; } else { AfxMessageBox(_T("D::DoModal() : LocalAllock Failed")); return -1; } }

                  L 1 Reply Last reply
                  0
                  • P prithaa

                    DLGTEMPLATE m_DialogTemplate;

                    int MFC::Dialog::DoModal() { //For OK and Cancel buttons?? m_DialogTemplate.cy+=(DlgControls.size()*4); AddOkCancel(); int iRet=0; //presetting for caption in the dialog.... int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL,0); int szBoxLen = cWC + 1; WCHAR *szBoxCaption = new WCHAR[szBoxLen]; // Copy the string... MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, (LPWSTR)szBoxCaption, cWC); szBoxCaption[cWC] = 0; szBoxLen = (cWC) * sizeof(WCHAR); int nBufferSize = sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) /*menu and class*/ + szBoxLen /*size of caption*/ + sizeof(WORD) /*fontsize*/ ;//+ nFontNameLen /*size of fontname*/; HLOCAL hLocal = LocalAlloc(LHND, nBufferSize); if (hLocal != NULL) { BYTE* pBuffer = (BYTE*)LocalLock(hLocal); if (pBuffer == NULL) { LocalFree(hLocal); AfxMessageBox(_T("D::DoModal() : LocalLock Failed")); } BYTE *pdest = pBuffer; // transfer DLGTEMPLATE structure to the buffer memcpy(pdest, &m_DialogTemplate, sizeof(DLGTEMPLATE)); // DLGTemplate pdest += sizeof(DLGTEMPLATE); *(WORD*)pdest = 0; // no menu -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment *(WORD*)(pdest + 1) = 0; // use default window class -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment memcpy(pdest, szBoxCaption, szBoxLen); // Caption pdest += szBoxLen; //These are the MFC functions, which do the job... InitModalIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd); iRet = CDialog::DoModal(); LocalUnlock(hLocal); LocalFree(hLocal); return iRet; } else { AfxMessageBox(_T("D::DoModal() : LocalAllock Failed")); return -1; } }

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #18

                    Well I guess you missed most of my message where I said: 1. Edit your message, i.e. the one where you posted the code. 2. Use <pre></pre> tags around your code. 3. Use the Preview button to check that what you have posted is correct.

                    Just say 'NO' to evaluated arguments for diadic functions! Ash

                    P 1 Reply Last reply
                    0
                    • L Lost User

                      Well I guess you missed most of my message where I said: 1. Edit your message, i.e. the one where you posted the code. 2. Use <pre></pre> tags around your code. 3. Use the Preview button to check that what you have posted is correct.

                      Just say 'NO' to evaluated arguments for diadic functions! Ash

                      P Offline
                      P Offline
                      prithaa
                      wrote on last edited by
                      #19

                      sorry i m posting code for the first time

                      int MFC::Dialog::DoModal()
                      {
                      //For OK and Cancel buttons??
                      m_DialogTemplate.cy+=(DlgControls.size()*4);

                      AddOkCancel();
                      
                      int iRet=0;
                      
                      //presetting for caption in the dialog....
                      	
                      int cWC = MultiByteToWideChar(CP\_ACP, 0, m\_strCaption, -1, NULL, 0);
                      int szBoxLen = cWC + 1;
                      WCHAR \*szBoxCaption = new WCHAR\[szBoxLen\];
                      // Copy the string...
                      MultiByteToWideChar(CP\_ACP, 0, m\_strCaption, -1, (LPWSTR) szBoxCaption, cWC);
                      szBoxCaption\[cWC\] = 0;
                      szBoxLen = (cWC) \* sizeof(WCHAR);
                      
                      int nBufferSize =  sizeof(DLGTEMPLATE) + (2 \* sizeof(WORD)) /\*menu and class\*/ + szBoxLen /\*size of caption\*/
                      	+ sizeof(WORD) /\*fontsize\*/ ;//+ nFontNameLen /\*size of fontname\*/;
                      
                      HLOCAL hLocal = LocalAlloc(LHND, nBufferSize);
                      if (hLocal != NULL) {
                      	BYTE\* pBuffer = (BYTE\*)LocalLock(hLocal);
                      	if (pBuffer == NULL) {
                      		LocalFree(hLocal);
                      		AfxMessageBox(\_T("D::DoModal() : LocalLock Failed"));
                      	}
                      
                      	BYTE \*pdest = pBuffer;
                      	// transfer DLGTEMPLATE structure to the buffer
                      	memcpy(pdest, &m\_DialogTemplate, sizeof(DLGTEMPLATE));	// DLGTemplate
                      	pdest += sizeof(DLGTEMPLATE);
                      	\*(WORD\*)pdest = 0;									// no menu					-- WORD to say it is 0 bytes
                      	pdest += sizeof(WORD);								// Increment
                      	\*(WORD\*)(pdest + 1) = 0;							// use default window class -- WORD to say it is 0 bytes
                      	pdest += sizeof(WORD);								// Increment
                      	memcpy(pdest, szBoxCaption, szBoxLen);			// Caption
                      	pdest += szBoxLen;
                      	
                      	//These are the MFC functions, which do the job...
                      
                      	InitModalIndirect((LPDLGTEMPLATE)pBuffer, m\_pParentWnd);
                      	iRet = CDialog::DoModal();
                      	
                      	LocalUnlock(hLocal);
                      	LocalFree(hLocal);
                      	return iRet;
                      }
                      else {
                      	AfxMessageBox(\_T("D::DoModal() : LocalAllock Failed"));
                      	return -1;
                      }
                      

                      }

                      P 1 Reply Last reply
                      0
                      • P prithaa

                        sorry i m posting code for the first time

                        int MFC::Dialog::DoModal()
                        {
                        //For OK and Cancel buttons??
                        m_DialogTemplate.cy+=(DlgControls.size()*4);

                        AddOkCancel();
                        
                        int iRet=0;
                        
                        //presetting for caption in the dialog....
                        	
                        int cWC = MultiByteToWideChar(CP\_ACP, 0, m\_strCaption, -1, NULL, 0);
                        int szBoxLen = cWC + 1;
                        WCHAR \*szBoxCaption = new WCHAR\[szBoxLen\];
                        // Copy the string...
                        MultiByteToWideChar(CP\_ACP, 0, m\_strCaption, -1, (LPWSTR) szBoxCaption, cWC);
                        szBoxCaption\[cWC\] = 0;
                        szBoxLen = (cWC) \* sizeof(WCHAR);
                        
                        int nBufferSize =  sizeof(DLGTEMPLATE) + (2 \* sizeof(WORD)) /\*menu and class\*/ + szBoxLen /\*size of caption\*/
                        	+ sizeof(WORD) /\*fontsize\*/ ;//+ nFontNameLen /\*size of fontname\*/;
                        
                        HLOCAL hLocal = LocalAlloc(LHND, nBufferSize);
                        if (hLocal != NULL) {
                        	BYTE\* pBuffer = (BYTE\*)LocalLock(hLocal);
                        	if (pBuffer == NULL) {
                        		LocalFree(hLocal);
                        		AfxMessageBox(\_T("D::DoModal() : LocalLock Failed"));
                        	}
                        
                        	BYTE \*pdest = pBuffer;
                        	// transfer DLGTEMPLATE structure to the buffer
                        	memcpy(pdest, &m\_DialogTemplate, sizeof(DLGTEMPLATE));	// DLGTemplate
                        	pdest += sizeof(DLGTEMPLATE);
                        	\*(WORD\*)pdest = 0;									// no menu					-- WORD to say it is 0 bytes
                        	pdest += sizeof(WORD);								// Increment
                        	\*(WORD\*)(pdest + 1) = 0;							// use default window class -- WORD to say it is 0 bytes
                        	pdest += sizeof(WORD);								// Increment
                        	memcpy(pdest, szBoxCaption, szBoxLen);			// Caption
                        	pdest += szBoxLen;
                        	
                        	//These are the MFC functions, which do the job...
                        
                        	InitModalIndirect((LPDLGTEMPLATE)pBuffer, m\_pParentWnd);
                        	iRet = CDialog::DoModal();
                        	
                        	LocalUnlock(hLocal);
                        	LocalFree(hLocal);
                        	return iRet;
                        }
                        else {
                        	AfxMessageBox(\_T("D::DoModal() : LocalAllock Failed"));
                        	return -1;
                        }
                        

                        }

                        P Offline
                        P Offline
                        prithaa
                        wrote on last edited by
                        #20

                        thanks for helping

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups