Dialog from Toolbar

Hello,

I have a working IE toolbar that can do most everything that I want it to. However, I need to be able to click on a button on the toolbar and have a dialog pop up where the user can fill in some information. My application crashes when I try to do this in the many different ways that I have tried. I am trying to use the CDialog class and have created a Dialog resource that looks the way I want it to.

The crash is an ASSERT in afxwin1.inl

_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{ ASSERT(afxCurrentResourceHandle != NULL);
return afxCurrentResourceHandle; }

This is how I am trying to create the window:

CDialog addone(IDD_DIALOG1);
addone.DoModal();

Any help is greatly appreciated, thank you!

Mike
[805 byte] By [Rummey] at [2007-11-19 7:13:32]
# 1 Re: Dialog from Toolbar
Hello Mike, it is may be a stupid question but are u using a DLL ?
Malan at 2007-11-11 0:28:13 >
# 2 Re: Dialog from Toolbar
I take it this is inside a Browser Helper Object, correct?

When you say it crashes, what exactly are the symptoms? Can you run it in the debugger and determine which line causes the fault?
hankdane at 2007-11-11 0:29:13 >
# 3 Re: Dialog from Toolbar
Yes, I am creating a DLL, which is ran through IE to make the toolbar.

The crash is by an assertion.

about.DoModal();

That line executes, which is a CDialog function and the next thing that occurs is an assertion from afxwin1.inl. The exact line is:

_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{ ASSERT(afxCurrentResourceHandle != NULL);
return afxCurrentResourceHandle; }

What appears to be happening is that the CDialog does not know the handle for the window that the dialog is going to pop up in (either IE or my toolbar, I am unsure).

This is a small part of a larger oper source project, and unfortunately there are very little open source IE Toolbars out there.

Mike
Rummey at 2007-11-11 0:30:12 >
# 4 Re: Dialog from Toolbar
Here is an update:

If I do the

about = new CDialog(IDD_DIALOG1, (CWnd*)pWnd);
about->DoModal();

in the Create function of my CToolBarCtrl class then the dialog pops up perfectly. If I do it anytime after the create, it crashes as I have described.

How can I get it so the dialog will open anytime?

Mike
Rummey at 2007-11-11 0:31:09 >
# 5 Re: Dialog from Toolbar
Typically, this problem occurs because the application is not properly initialized with AfxWinInit(), or because there is no _Module object.

In your case, it's possible you may have to callAFX_MANAGE_STATE ( http://msdn.microsoft.com/library/en-us/vclib/html/_mfc_afx_manage_state.asp).
hankdane at 2007-11-11 0:32:10 >
# 6 Re: Dialog from Toolbar
Hankdane: Can you be more specific on this? I tried reading up and used a couple examples but nothing seems to help.

Should I be making this call in my Create function? Or do I have to make one of these calls right before I try to create the dialog?

I do have a variable CComModule _Module;

I am calling AFX_MANAGE_STATE: AFX_MANAGE_STATE(AfxGetStaticModuleState()); when the toolbar is created.

I am not calling AfxWinInit anywhere.

Thanks so much!

Mike
Rummey at 2007-11-11 0:33:20 >
# 7 Re: Dialog from Toolbar
I got this problem solved!

I had to add "AFX_MANAGE_STATE(AfxGetStaticModuleState());" at the top of every function that tried a CDialog. Why it has to be the very top, I don't know, but it made a difference.

Thanks to everyone that checked out my post!

Mike
Rummey at 2007-11-11 0:34:16 >