Results 1 to 10 of 10

Thread: My Dll is unable to load resources !?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46

    My Dll is unable to load resources !?

    I don`t know the reason but my dll isn`t be able to load resources. Even that simple code below, fails.
    CString str;
    str.LoadResource(IDS_MYSTR);

    I tried to create a modal dialog but it also failed to load resource of the dialog template.
    CDialog myDlg(IDD_DIALOG_MYDLG);
    myDlg.DoModal(); // Returns -1

    I even tried to write;

    CDialog *pMyDlg = new CDialog;
    pMyDlg->Create(IDD_DIALOG_MYDLG); //Create(...) asserts


    in dlgcore.cpp

    BOOL CDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
    {
    ASSERT(IS_INTRESOURCE(lpszTemplateName) || AfxIsValidString(lpszTemplateName));

    m_lpszTemplateName = lpszTemplateName; // used for help
    if (IS_INTRESOURCE(m_lpszTemplateName) && m_nIDHelp == 0)
    m_nIDHelp = LOWORD((DWORD_PTR)m_lpszTemplateName);

    #ifdef _DEBUG
    if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE))
    {


    ASSERT(FALSE); // invalid dialog template

    !!!! DEBUGGER STOPS EXECUTION {AFTER THE ASSERT(FALSE)} HERE !!!!!!

    namePostNcDestroy(); // cleanup if Create fails too soon
    return FALSE;
    }
    #endif //_DEBUG

    ......
    .....
    }

    I don`t know how to overcome that problem. If you have experienced the same problem and/or know the solution, would you please let me know

    Thanks in advance

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Are you absolutly sure that the resource script is in your project and contains all the resources you load?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    There is also something with the resource instance handle in MFC, but I don't know much about that. Have you tried tracing with a debugger through the LoadString call?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46
    Firstly, thanks for your reply.

    I rechecked the resources and didn`t find any mistake.

    I put a breakpoint on the code

    CDialog myDlg(IDD_DIALOG_MYDLG);

    and in the Locals window:

    myDlg
    - CDialog
    - m_lpszTemplateName 0x00000007 <Bad Ptr> const char *


    IDD_DIALOG_MYDLG is defined as 7 and the value of m_lpszTemplateName is correct, so I even don`t know why it`s a bad pointer.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It's an invalid pointer, but that's ok because it isn't *used* as one (see the documentation...).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46
    The bad prt m_lpszTemplateName is the reason of the assertion
    see below:

    // in CDialog::Create(...)

    #ifdef _DEBUG
    if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE)) // m_lpszTemplateName is equal to lpszTemplateName
    {
    ASSERT(FALSE); // invalid dialog template

    !!!! DEBUGGER STOPS EXECUTION {AFTER THE ASSERT(FALSE)} HERE !!!!!!

    namePostNcDestroy(); // cleanup if Create fails too soon
    return FALSE;
    }
    #endif //_DEBUG

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46
    Debugger traces
    ERROR: Cannot find dialog template with IDD 0x0007.

    BOOL AFXAPI _AfxCheckDialogTemplate(LPCTSTR lpszResource, BOOL bInvisibleChild)
    {
    ASSERT(lpszResource != NULL);
    HINSTANCE hInst = AfxFindResourceHandle(lpszResource, RT_DIALOG);
    HRSRC hResource = ::FindResource(hInst, lpszResource, RT_DIALOG); // FindResource or AfxFindResourceHandle is unsuccessful
    if (hResource == NULL)
    {
    if (DWORD_PTR(lpszResource) > 0xffff)
    TRACE(traceAppMsg, 0, _T("ERROR: Cannot find dialog template named '%s'.\n"),
    lpszResource);
    else
    TRACE(traceAppMsg, 0, "ERROR: Cannot find dialog template with IDD 0x%04X.\n",
    LOWORD((DWORD_PTR)lpszResource));
    return FALSE;
    }

    .............
    ............
    ...........
    }


    BTW, You`re right Parksie, m_lpszTemplateName is OK.


    In that case I realized that MFC is hell.
    Last edited by might; Nov 23rd, 2002 at 11:19 AM.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Are you sure that AfxFindResourceHandle returns a valid value?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46
    I realized the problem.
    When I call AfxGetResourceHandle() in CWinApp::InitInstance() of my DLL it returns 0x490000. Resource handle of the main executable is 0x400000. And When I call AfxGetResourceHandle() in an exported function of the Dll, it returns 0x400000; the resource handle of the exe, not the dll !?

    So, When the Dll tries to load a resource, it tries to find in the main executable`s. Thus, that becomes almost impossible to load it.
    Last edited by might; Nov 24th, 2002 at 07:04 AM.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    That's what I guessed. You can set this handle with AfxSetResourceHandle, but you have to reset it after loading, else all subsequent resource loading ops in the main exe will fail...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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