MFC Dialog box not working - VC6 upgrade
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: MFC Dialog box not working - VC6 upgrade

  1. #1
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Unhappy MFC Dialog box not working - VC6 upgrade

    Large project that I've been working on converting from VC++ 6.0 to VC++ 8.0 (.NET 2005). It has an app (EXE), a main DLL, and 5 component DLLs (formerly COM, but now are MFC Dlls).

    One of the DLLs has many dialogs and controls that are used. When I converted over, I just copied most of the resource file (.rc) over to the new one (textually).

    Everything looks fine. All dialog boxes and controls appear fine when I look at the resources in the project.

    When I get to the point in my code where a dialog box is called, nothing happens. Nothing comes up, it just goes over the line returning a -1.

    Relevant Code:

    Code:
          CSequenceSelectDialog dlg;
          dlg.m_pTestProperties = m_pTestProperties;
          dlg.m_pConfigurationMatrix = m_pConfigurationMatrix;
          dlg.m_nStationNumber = nStationNumber;
          dlg.m_strUserPath = m_strUserPath;
          dlg.m_strTestPath = m_strTestPath;
    before .NET conversion */
          *nSequenceSelection = m_nSequenceSelection = (int) dlg.DoModal();
          if (*nSequenceSelection == IDOK)
          {
    Is there any reason this isn't working now that you can think of? Any thoughts are appreciated.

  2. #2
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: MFC Dialog box not working - VC6 upgrade

    Went further and debugged in to Windows code.

    This is the DoModal() code.

    Code:
    INT_PTR CDialog::DoModal()
    {
    	// can be constructed with a resource template or InitModalIndirect
    	ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
    		m_lpDialogTemplate != NULL);
    
    	// load resource as necessary
    	LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
    	HGLOBAL hDialogTemplate = m_hDialogTemplate;
    	HINSTANCE hInst = AfxGetResourceHandle();
    	if (m_lpszTemplateName != NULL)
    	{
    		hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
    		HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
    		hDialogTemplate = LoadResource(hInst, hResource);
    	}
    It looks like the ::FindResource doesn't fine anything. hResource is NULL returning from that routine.

    GetLastError returns: 1812 - ERROR_RESOURCE_DATA_NOT_FOUND (The specified image file did not contain a resource section.)
    Last edited by KingTermite; May 7th, 2009 at 06:31 PM.

  3. #3
    Join Date
    Apr 1999
    Posts
    27,426

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by KingTermite View Post
    Is there any reason this isn't working now that you can think of?
    The code you posted will not help, as all it does is show us that your syntax is OK. It doesn't tell us what is happening at runtime or anything else that would give any indication what the problem is.

    If this were a VC 6.0 application, what reasons are there for returning a -1 for DoModal()? Whatever those reasons are, did you investigate whether those are the same reasons with your current application?

    One reason is that a control in your dialog is not available or not set up properly. The easiest way to detect this is to remove all controls from the dialog, temporarily comment out any code that might refer to the controls, and see if the empty dialog displays correctly when you run the application. If it does, then add controls one at a time until it breaks.

    On a side note, this is suspicious:
    Code:
    *nSequenceSelection
    Did you initialize this pointer? If you didn't, that code where you are setting the return value of DoModal is faulty.

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Apr 1999
    Posts
    27,426

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by KingTermite View Post
    Went further and debugged in to Windows code.
    What is the value of hInst? Is it the handle to the module that contains the dialog resource? If not, that is the reason for the error.

    What is m_lpszTemplateName? Is it the name of the dialog resource? If not, again, an error.

    When you compiled, did the resource compiler actually compile any resources?

    When you open the DLL in a resource editor, do you see the dialog as one of the resources (I believe you can do this with Visual Studio by specifying that you are opening the DLL as a resource).

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by Paul McKenzie View Post
    What is the value of hInst? Is it the handle to the module that contains the dialog resource? If not, that is the reason for the error.

    What is m_lpszTemplateName? Is it the name of the dialog resource? If not, again, an error.

    When you compiled, did the resource compiler actually compile any resources?

    When you open the DLL in a resource editor, do you see the dialog as one of the resources (I believe you can do this with Visual Studio by specifying that you are opening the DLL as a resource).

    Regards,

    Paul McKenzie
    hInst => 0x05C90000 (unused)

    I'm not sure the DLL handle, but the 'unused' makes me think it isn't the DLLs handle.

    m_lpszTemplateName = 0x000000d0 <Bad Ptr>

    Again, "Bad Ptr" doesn't look good.


    Ok, looking closer at the copmiler statements and I think I see what you mean;

    Code:
    1>Generating Code...
    1>Compiling resources...
    1>Linking...
    That looks like no resources are getting compiled.

    OK, how do I fix that? What to look at to get those compiled?

  6. #6
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by Paul McKenzie View Post
    When you open the DLL in a resource editor, do you see the dialog as one of the resources (I believe you can do this with Visual Studio by specifying that you are opening the DLL as a resource).

    Regards,

    Paul McKenzie
    Resource editor? Is that a VS tool?

  7. #7
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: MFC Dialog box not working - VC6 upgrade

    Ok, I downloaded a resource editor once I figured out what you meant (and that it was a separate program).

    The resource editor shows the dialog components in the DLL just fine.

  8. #8
    Join Date
    Apr 1999
    Posts
    27,426

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by KingTermite View Post
    Resource editor? Is that a VS tool?
    If you do a File / Open in Visual Studio, and you open the DLL file you claim has the resource, the DLL file will be loaded, and you will see the resources.

    Regards,

    Paul McKenzie

  9. #9
    Join Date
    Apr 1999
    Posts
    27,426

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by KingTermite View Post
    Ok, I downloaded a resource editor once I figured out what you meant (and that it was a separate program).

    The resource editor shows the dialog components in the DLL just fine.
    What is the resource ID of the dialog? Is it numeric, or is it a string name?

    Regards,

    Paul McKenzie

  10. #10
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by Paul McKenzie View Post
    What is the resource ID of the dialog? Is it numeric, or is it a string name?

    Regards,

    Paul McKenzie
    All the resource IDs looked numeric. Each dialog had a number associated with it.
    Last edited by KingTermite; May 7th, 2009 at 07:24 PM.

  11. #11
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: MFC Dialog box not working - VC6 upgrade

    Have to run home (late day already)....hopefully pick back up on this tomorrow. Thanks for the help so far.

  12. #12
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,526

    Re: MFC Dialog box not working - VC6 upgrade

    Check out AFX_MANAGE_STATE here
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  13. #13
    Join Date
    Apr 1999
    Posts
    27,426

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by KingTermite View Post
    All the resource IDs looked numeric. Each dialog had a number associated with it.
    Where does the code come from in your first post? The resource certainly cannot be found in that module where the code you posted comes from.

    A DLL that contains resources must be loaded at runtime via LoadLibrary by the application. Is this how you're accessing the resources in the DLL?

    Regards,

    Paul McKenzie

  14. #14
    Join Date
    Apr 1999
    Posts
    27,426

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by VladimirF View Post
    Check out AFX_MANAGE_STATE here
    Yep, we're thinking on the same level. The MFC way to do the LoadLibrary is the AFX_MANAGE_STATE.

    Regards,

    Paul McKenzie

  15. #15
    Join Date
    Apr 1999
    Posts
    27,426

    Re: MFC Dialog box not working - VC6 upgrade

    Quote Originally Posted by KingTermite View Post
    All the resource IDs looked numeric. Each dialog had a number associated with it.
    And 0xd0 in the FindResource is 208, so the dialog being searched for is correct, in terms of ID.

    Therefore the most probable reason is what Vladimir and myself pointed out -- the module where that code is being called from does not have the resources embedded within it -- it needs to go to an "external" library for the resource.

    To do that using MFC, the AFX_MANAGE_STATE sets the resource handle (the hInst in the FindResource) to the instance handle of the DLL that contains the resources.

    The Windows API way to do this is to call LoadLibrary() and store the HINSTANCE that is returned -- this then becomes the "hInst" in the FindResource function.

    Regards,

    Paul McKenzie

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center