CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2008
    Posts
    98

    [RESOLVED] CDialog::Create return fails, saying can't find the IDD resource of the dialog

    forgive me, please allow me to start from the begining.
    I choose win32 project to create an empty project.
    Then I import some existing codes to the project.(a Main.cpp file with WinMain, CMyDlg.h and CMyDlg.cpp file
    implementing a dialog class CMyDlg, the CMyDlg.h having line enum{IDD = IDD_MYDLG})
    Then I compile the codes, for I copy the IDD_MYDLG's defines in my .h file, so it compiles fine.

    Then I notice, I've never renew a .rc file to create a dialog resource.
    So I start from menu 'Insert'->'Resource' to create a dialog resource. and name the dialog resource
    IDD_MYDLG.

    In Main.cpp I declare a CMyDlg *ptrDlg;
    Code:
    ptrDlg = new CMyDlg;
    if (ptrDlg)
    {
    	BOOL bRet = FALSE;
    	bRet = ptrDlg->Create(CMyDlg::IDD);
    }
    But I still debug to find ptrDlg->Create return FALSE.
    Then debug to follow, found the code here dlgcore.cpp
    Code:
    BOOL AFXAPI _AfxCheckDialogTemplate(LPCTSTR lpszResource, BOOL bInvisibleChild)
    {
    	ASSERT(lpszResource != NULL);
    	HINSTANCE hInst = AfxFindResourceHandle(lpszResource, RT_DIALOG);-->Saying can't find the resource
    	HRSRC hResource = ::FindResource(hInst, lpszResource, RT_DIALOG);
    Saying can't find the resource.
    I've add the resource, I can't clear my mind to figure out where's wrong.
    Please help me unlock my mind!

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: CDialog::Create return fails, saying can't find the IDD resource of the dialog

    First, if you are using MFC stuff in a Win32 application you have to initialize MFC:
    Code:
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                           HINSTANCE hPrevInstance,
                           LPTSTR    lpCmdLine,
                           int       nCmdShow)
    {
       if(! AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) 
       { 
          TRACE0("Initializing MFC failed"); 
          return -1; 
       } 
        // ...
        return 0;
    }
    If the problem still persists, check in resource.h to have unique resource ID values.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Jan 2008
    Posts
    98

    Re: [RESOLVED] CDialog::Create return fails, saying can't find the IDD resource of th

    Thx very much.
    It does work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured