integer divide by zero in CreateDlgIndirect()
I experience an integer divide by zero while trying to create a
modeless
dialog from an mfc-dll that is called from a windowless exe. I tried
to
give a step-by-step overview and hope someone can explain what causes
this error and what can be done about it. TIA, ~.rhavin;)
=====================================================
1. windowless exe loads dll, calling InitInstance()
HINSTANCE is 0x10000000.
2. InitInstance() registers HWND_MESSAGE-parent'ed msg-window
3. Msg-window opened (only window that app has now)
4. Message send to msg-window "please open dialog (whatever)"
5. Message correctly received by msg-loop and appropriate fn called,
that looks like the following:
_______________________________________________________
void CFZGUIManager::DlgMessage()
{
CQDlgMessage* pDlg = new CQDlgMessage;
VERIFY(pDlg->Create());
// ... //
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6. Dialog allocated (new) CQDlgMessage ctor called.
7. CQDlgMessage is a public CQDialog that is a public CDialog
CQDialog has following ctor and saves its ResourceID:
_______________________________________________________
CQDialog::CQDialog(UINT nResourceID, CWnd* pParent) :
m_nResourceID(nResourceID), CDialog(nResourceID, pParent) {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7. CQDialog has a Create() fn that looks like this:
______________________________________________________
bool CQDialog::Create(CWnd* pParent)
if (pParent == NULL)
pParent = AfxGetMainWnd();
if (pParent == NULL)
pParent = GetDesktopWindow();
// #: * see below* //
return (CDialog::Create(m_nResourceID, pParent) != FALSE);
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8. At "#", the pParent is set to desktop, because app has no
main window (pParent = [CTempWnd hWnd=0x00010014]).
9. CDialog::Create() is called with correct RsrcID.
10. in CDialog::Create(), AfxFindResourceHandle() is called,
returning HINSTANCE 0x10000000, then FindResource() and
LoadResource() are called, both returning values != NULL
11. Now CreateIndirect() is called.
hDialogTemplate is 0x101b52b0
pParentWnd is 0x0099d5c0 (hWnd = 0x00010014, Desktop)
hInstance is 0x10000000
12. hDialogTemplate is locked (LockResource()) and another
CreateIndirect() overload is called witch calles (finally!)
CreateDlgIndirect(), where the following happens:
( a # marks my own comments ...)
______________________________________________________
BOOL CWnd::CreateDlgIndirect(LPCDLGTEMPLATE
lpDialogTemplate, CWnd* pParentWnd, HINSTANCE hInst)
{
ASSERT(lpDialogTemplate != NULL); //# -> OK
if (pParentWnd != NULL)
ASSERT_VALID(pParentWnd); //# -> OK
if (hInst == NULL) //# -> hInst != NULL
hInst = AfxGetInstanceHandle();
_AFX_OCC_DIALOG_INFO occDialogInfo;
COccManager* pOccManager = afxOccManager; //# ->NULL
HGLOBAL hTemplate = NULL;
HWND hWnd = NULL;
DWORD dwError = 0;
TRY
{
VERIFY(AfxDeferRegisterClass(
AFX_WNDCOMMCTLS_REG)
); //# -> OK
AfxDeferRegisterClass(
AFX_WNDCOMMCTLSNEW_REG
); //# -> seems ok
if (pOccManager != NULL)
{
//# ... is NULL, so nothing done here! ... #//
}
if (lpDialogTemplate == NULL) //# -> is != NULL
return FALSE;
// If no font specified, set the system font.
CString strFace;
WORD wSize = 0;
BOOL bSetSysFont = !CDialogTemplate::GetFont(
lpDialogTemplate, strFace, wSize);
//# -> bSetSysFont set to FALSE
//#... some stuff not called omitted here ... #//
// setup for modal loop and creation
m_nModalResult = -1;
m_nFlags |= WF_CONTINUEMODAL;
//# m_nFlags now == WF_CONTINUEMODAL;
// create modeless dialog
AfxHookWindowCreate(this); //# -> seems OK
//# ++++++++++++++++++++++++++++++++++++++++++++
//# following call (cant trace it any further) gives this message:
//# "Unhandled exeption in [myApp] (NTDLL.DLL):
//# 0xC0000094: Integer Divide by Zero"
//# ++++++++++++++++++++++++++++++++++++++++++++
hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate,
pParentWnd->GetSafeHwnd(), AfxDlgProc);
// ...... //
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~