Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Visual C++ 6.0 CDialog::Create fails (returns 0)

685 views
Skip to first unread message

Kman

unread,
Sep 26, 2007, 6:36:42 PM9/26/07
to
I don't understand what could cause this? Pass in a valid ID and the
current object (this).

if( !m_pControlDlg ) {
m_pControlDlg = new CControlDlg();
ASSERT( m_pControlDlg );
ASSERT( AfxIsValidAddress( m_pControlDlg ,
sizeof( CControlDlg ) ) );

bool bCreated = m_pControlDlg->Create( IDD_DIALOG_CONTROL, this );
ASSERT(bCreated);////this is where my failure occures
m_pControlDlg->ShowWindow( SW_SHOWNORMAL );
}

Any ideas?


I appreciate any ideas you could give.

Thanks.

David Ching

unread,
Sep 26, 2007, 7:00:01 PM9/26/07
to
"Kman" <kma...@yahoo.com> wrote in message
news:1190846202....@g4g2000hsf.googlegroups.com...

>I don't understand what could cause this? Pass in a valid ID and the
> current object (this).
>
> if( !m_pControlDlg ) {
> m_pControlDlg = new CControlDlg();
> ASSERT( m_pControlDlg );
> ASSERT( AfxIsValidAddress( m_pControlDlg ,
> sizeof( CControlDlg ) ) );
>
> bool bCreated = m_pControlDlg->Create( IDD_DIALOG_CONTROL, this );
> ASSERT(bCreated);////this is where my failure occures
> m_pControlDlg->ShowWindow( SW_SHOWNORMAL );
> }
>

Did your CControlDlg::OnInitDialog() and CControlDlg::OnCreate() get called?
Trace into the m_pControlDlg->Create() call and see what MFC is doing with
it.

-- David


Michael K. O'Neill

unread,
Sep 26, 2007, 9:57:46 PM9/26/07
to

"Kman" <kma...@yahoo.com> wrote in message
news:1190846202....@g4g2000hsf.googlegroups.com...

Try a call to GetLastError() and see what you get.

According to the docs on the basic API's ::CreateWindow() function, the call
can fail for
- an invalid parameter value
- the system class was registered by a different module
- The WH_CBT hook is installed and returns a failure code
- if one of the controls in the dialog template is not registered, or its
window window procedure fails WM_CREATE or WM_NCCREATE

The last one sounds like it might be pertinent. Maybe your dialog is
hosting a child control that is failing its OnCreate() handler. Or maybe
your dialog is hosting a rich edit without a prior call to
AfxInitRichEdit().


Joseph M. Newcomer

unread,
Sep 27, 2007, 1:38:24 AM9/27/07
to
Do you have a rich edit control in your dialog? If so, did you add AfxInitRichEdit() to
your InitInstance handler? Are you using ActiveX controls? Are they registered?

As already pointed out, you have failed to tell us what ::GetLastError said, and you have
to find this out BEFORE the ASSERT happens (one of the bug reports I filed years ago and
which STILL has not been fixed is that ASSERT changes the ::GetLastError value, which is a
serious design error with ASSERT). So you have to set a breakpoint at the ASSERT
statement and look at the value
ERR,hr
in a watch window.

You can also set the no-fail-create style on the dialog and see if it creates; if it does,
some control is missing, and that's your problem.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Kman

unread,
Sep 27, 2007, 9:32:15 AM9/27/07
to
> email: newco...@flounder.com
> Web:http://www.flounder.com
> MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
>
> - Show quoted text -

I tried GetLastError (never used it before)....I get the value of 0
and in the watch box I have:
@err,hr S_OK
@err 0x00000000

you can see where I added it below.

But I did tried the no-fail-create style in the dialog option and it
did go to the OnInitDialog, which it did not do before. So it
executed more of the code, but still did not show the dialog. So if
there is anymore insight on why the no-fail-create would allow more of
the code to be executed, but still not display that would appreciated.

if( !m_pControlDlg ) {
m_pControlDlg = new CControlDlg();
ASSERT( m_pControlDlg );
ASSERT( AfxIsValidAddress( m_pControlDlg ,
sizeof( CControlDlg ) ) );


bool bCreated = m_pControlDlg-
>Create( IDD_DIALOG_CONTROL, this );

DWORD error = GetLastError();///the value this returns
is 0

Kman

unread,
Sep 27, 2007, 9:41:40 AM9/27/07
to

The OnInitDialog does not get called (unless I set no-fail-create
style), is that weird or better yet do you know why that would be? I
don't have a OnCreate() for my dialog, but there is one for the parent
dialog, so do I need one too? I have the constructor called and that
executes. I am working with existing stuff and only the main dialog
has a OnCreate.

jmarc

unread,
Sep 27, 2007, 9:44:45 AM9/27/07
to

"Kman" <kma...@yahoo.com> wrote in message
news:1190846202....@g4g2000hsf.googlegroups.com...

Look if any other IDs are using the same number
as IDD_DIALOG_CONTROL have.

A simple test might be trying a different number ID for
for IDD_DIALOG_CONTROL ...

a simple try ...: bool bCreated = m_pControlDlg->Create( 777, this );

jmarc...

Kman

unread,
Sep 27, 2007, 10:04:38 AM9/27/07
to
> > Thanks.- Hide quoted text -

>
> - Show quoted text -

I found the issue I have a costum control box and it doesn't like
that....I need to investigate why...I am probably missing a
initialization of the costum box. So unless you know what that would
need to be, thanks for the help.

jmarc

unread,
Sep 27, 2007, 11:12:44 AM9/27/07
to

"Kman" <kma...@yahoo.com> wrote in message
news:1190901878.0...@g4g2000hsf.googlegroups.com...

.. or it is related with 'this' ou pass to Create...
The class within your code is calling Create and passing 'this'
must be derived from a common base class somewhere in the
hiearchy.

If it is not, I supposed you should pass NULL instead of 'this'
bool bCreated = m_pControlDlg->Create( IDD_DIALOG_CONTROL, NULL);

jmarc...


Joseph M. Newcomer

unread,
Sep 27, 2007, 12:52:45 PM9/27/07
to
If no-fail-create allows you to get to OnInitDialog, it means that some control in your
dialog uses a window class that is not registered, or a rich edit control without
AfxInitRichEdit, or is missing an ActiveX control. At that point, your ShowWIndow code
should have caused the partially-constructed dialog to appear. If you are using control
variables (as opposed to the mistake of using GetDlgItem everywhere) you should then get
an assertion failure on a DDX_Control call because it can't find the window with that ID.

So we now know where to look, but I don't know why ShowWindow doesn't work, unless you
have something else that is killing the dialog off.
joe

email: newc...@flounder.com

Joseph M. Newcomer

unread,
Sep 27, 2007, 12:54:10 PM9/27/07
to
Almost certainly because the class has not yet been registered.
joe

Joseph M. Newcomer

unread,
Sep 27, 2007, 12:55:42 PM9/27/07
to
That's the expected behavior. That's what no-fail-create is all about. It lets you get
to OnInitDialog even if there has been a creation error on a control.
joe

0 new messages