Static Library Containing Dialog and Resource
From: Boogie With Stu (YoHoHoHo_and_a_bottle_of_rum_at_pirate.com)
Date: 05/11/04
- Next message: Joseph M. Newcomer: "Re: Data Transfer Among Dialogs, Views, and Documents"
- Previous message: Joseph M. Newcomer: "Re: Turning off some messages - is it possible? Is it unnecessary?"
- Next in thread: David Lowndes: "Re: Static Library Containing Dialog and Resource"
- Reply: David Lowndes: "Re: Static Library Containing Dialog and Resource"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 11 May 2004 01:56:56 GMT
I have a static library that links with the static MFC lib. In this
library I create a CDialog and display it. I'm using
InitModalIndirect() to create the dialog from a resource template.
The resource template is in a BYTE array within the library.
Everything works great with the debug build. The dialog displays and
handles messages, etc. But when the calling app that links in the
static library (a straight Win32 app in this case) exits it gives an
Access Violation. Well, this only happens in release build and not
the debug build (of course, sigh).
I double checked my run-time libs and they all match correctly. I'm
completely stumped as I can't seem to figure out what causes the
Access Violation - nothing odd shows up in the debug build. Ran the
code through BoundsChecker and still no issues (in debug). In release
BoundsChecker just tells me there was an Access Violation when the app
exits.
Here's the function in the static lib that creates the dialog:
CWinApp theApp;
//Entry Function
int ShowDlg()
{
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, "", 0))
{
return 0; //failed
}
if (!AfxGetApp()->InitInstance())
{
if(AfxGetApp()!=NULL)
{
AfxGetApp()->ExitInstance();
}
AfxWinTerm();
return 0; // Init Failed
}
//create the dialog and show it
CDlgTempl* dlg = new CDlgTempl;
dlg->InitModalIndirect(dlg->GetTemplate());
dlg->DoModal();
delete dlg;
if(AfxGetApp()!=NULL)
{
AfxGetApp()->ExitInstance();
return 0;
}
// Terminate the library before destructors are called
AfxWinTerm();
return 1;
}
The GetTemplate() method of CDlgTempl returns a LPCDLGTEMPLATE.
All the above code runs fine in both builds. It is when the calling
app exits with the release build I get the Access Violation. No
linker warnings exist either. Everything seems clean.
Here's the calling app:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
return ShowDlg();
}
Any ideas??? I'm stumped. I had lots of debug code in there so I was
able to narrow down the access violation to the exit of WinMain.
-- Boogie With Stu
- Next message: Joseph M. Newcomer: "Re: Data Transfer Among Dialogs, Views, and Documents"
- Previous message: Joseph M. Newcomer: "Re: Turning off some messages - is it possible? Is it unnecessary?"
- Next in thread: David Lowndes: "Re: Static Library Containing Dialog and Resource"
- Reply: David Lowndes: "Re: Static Library Containing Dialog and Resource"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|