-
May 7th, 2009, 06:07 PM
#1
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.
-
May 7th, 2009, 06:24 PM
#2
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.
-
May 7th, 2009, 06:25 PM
#3
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by KingTermite
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
-
May 7th, 2009, 06:29 PM
#4
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by KingTermite
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
-
May 7th, 2009, 06:50 PM
#5
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by Paul McKenzie
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?
-
May 7th, 2009, 06:52 PM
#6
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by Paul McKenzie
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?
-
May 7th, 2009, 07:04 PM
#7
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.
-
May 7th, 2009, 07:08 PM
#8
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by KingTermite
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
-
May 7th, 2009, 07:09 PM
#9
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by KingTermite
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
-
May 7th, 2009, 07:19 PM
#10
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by Paul McKenzie
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.
-
May 7th, 2009, 07:25 PM
#11
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.
-
May 7th, 2009, 07:26 PM
#12
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:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
May 7th, 2009, 07:29 PM
#13
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by KingTermite
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
-
May 7th, 2009, 07:31 PM
#14
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by VladimirF
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
-
May 7th, 2009, 07:38 PM
#15
Re: MFC Dialog box not working - VC6 upgrade
Originally Posted by KingTermite
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|