How can I create dialog with ActiveX control in MFC supported console application?

I writing a console application with MFC support.
I've craeted "CMyDialog : public CDialog" class.
this dialog has an ActiveX control.

When I'm calling CMyDialog.Create(IDD_MYDIALOG) the function failed, and I'm getting the following warning:

First-chance exception in MyApplication.exe (OLE32.DLL): 0xC0000005: Access Violation.
First-chance exception in MyApplication.exe (KERNEL32.DLL): 0x8001010D: (no name).
Warning: CreateDlgControls failed during dialog init.

Can someone help me?

How can I create this dialog sucessfully?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

How did you create your application? Can please explain in more detail what exactly you mean console application with MFC Support?
bacharAuthor Commented:

I've created it with Microsoft Visual Stodio 6.
I've created a new console application with the MSDEV wizard, one of the options is: Console Application with MFC support.

actually it adds several MFC header files to the Win32 Console application.
I was able to bring up a dialog box with a webbrowser ActiveX by adding this at the bottom of _tmain

   afxContextIsDLL= FALSE;  // else AfxOleInit fails
   BOOL fRet= AfxOleInit();

   CMyDialog dlg;
   theApp.m_pMainWnd= &dlg;

I can't find any documentation on afxContextIsDLL or why it has been set to TRUE, but AfxOleInit() must be called and the code in there will short-curcuit if afxContextIsDLL is TRUE.

-- Dan
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Dialogs that contain ActiveX controls are more difficult to create indirectly because they require additional information such as license keys and the initial states of properties. See below article:
HOWTO: Use a Dialog Template to Create a MFC Dialog with an ActiveX Control


The information in this article applies to:

The Microsoft Foundation Classes (MFC), included with:
Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.0, 6.0


It is possible to display a dialog from either a DIALOG resource or from a dialog template in memory. In the latter case, the dialog template is either constructed or loaded into memory and the dialog is created indirectly.

Dialogs that contain ActiveX controls are more difficult to create indirectly because they require additional information such as license keys and the initial states of properties. MFC requires that this additional information be provided as a DLGINIT resource. The Visual C++ resource editor creates this DLGINIT resource in the resource (.rc) file for each dialog containing an ActiveX control.

Both CDialog::CreateIndirect() and CDialog::InitModalIndirect() support using DLGINIT resources with dialog templates in memory. However, the DLGINIT parameter is not documented and by default is set to NULL. The complete prototypes for these functions are:

BOOL CDialog::CreateIndirect(LPCDLGTEMPLATE lpDialogTemplate, CWnd* pParentWnd, void* lpDialogInit, HINSTANCE hInst);

BOOL CDialog::InitModalIndirect(LPCDLGTEMPLATE lpDialogTemplate, CWnd* pParentWnd = NULL,void* lpDialogInit = NULL);

NOTE: Only the versions of these functions which take a LPCDLGTEMPLATE as the first parameter support passing a DLGINIT resource. The versions which take a HGLOBAL parameter do not support DLGINIT resources.

The following source shows how to load a DIALOG resource from memory and display it indirectly using a dialog template in memory. This function also uses the DLGINIT resource and will work with DIALOG resources that contain ActiveX controls.

void CMainFrame::OnMyModalDialogIndirect()
     DLGTEMPLATE* pTemplate;
     HINSTANCE hInst= AfxFindResourceHandle(
     if (hInst == NULL)
          TRACE("Cound not find resource in resource chain");
     HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(IDD_INDIRECT),
     ASSERT(hRsrc != NULL);

     HGLOBAL hTemplate = ::LoadResource(hInst, hRsrc);
     ASSERT(hTemplate != NULL);
     pTemplate = (DLGTEMPLATE*)::LockResource(hTemplate);

     //Load coresponding DLGINIT resource
     void* lpDlgInit;
     HGLOBAL hDlgInit = NULL;

     HRSRC hsDlgInit = ::FindResource(hInst, MAKEINTRESOURCE(IDD_INDIRECT),
     if (hsDlgInit != NULL)
          // load it
          hDlgInit = ::LoadResource(hInst, hsDlgInit);
          ASSERT(hDlgInit != NULL);

          // lock it
          lpDlgInit = ::LockResource(hDlgInit);
          ASSERT(lpDlgInit != NULL);

     //ToDo: Modify DLGTEMPLATE in memory if desired

     CDialog dlg;
     dlg.InitModalIndirect(pTemplate, NULL, lpDlgInit);  
     if (hDlgInit)
hi bachar,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
hi bachar,
Do you have any additional questions?  Do any comments need clarification?

-- Dan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

These questions are still open and our records show you logged in recently. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days. Please note that the recommended minimum for an "Easy" question is 50 points.

EXPERTS: Please leave your thoughts on this question here.


Community Support Moderator
Experts Exchange
Admin notified of user neglect. Force/accepted by

Community Support Moderator
Experts Exchange
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.