Solved

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

Posted on 2001-07-03
8
1,601 Views
Last Modified: 2013-11-20
Hi,
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?

Thanks,
Michael
0
Comment
Question by:bachar
8 Comments
 
LVL 4

Expert Comment

by:inpras
Comment Utility
How did you create your application? Can please explain in more detail what exactly you mean console application with MFC Support?
0
 

Author Comment

by:bachar
Comment Utility
O.k.

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.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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();
   AfxEnableControlContainer();

   CMyDialog dlg;
   theApp.m_pMainWnd= &dlg;
   dlg.DoModal();

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
0
 
LVL 2

Expert Comment

by:GloriousRain
Comment Utility
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:
<MSDN>
HOWTO: Use a Dialog Template to Create a MFC Dialog with an ActiveX Control

Q231591


--------------------------------------------------------------------------------
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

--------------------------------------------------------------------------------


SUMMARY
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.



MORE INFORMATION
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()
{
     //Load DLGTEMPLATE
     DLGTEMPLATE* pTemplate;
 
     HINSTANCE hInst= AfxFindResourceHandle(
                            MAKEINTRESOURCE(IDD_INDIRECT),RT_DIALOG);
     
     if (hInst == NULL)
     {
          TRACE("Cound not find resource in resource chain");
          ASSERT(FALSE);
          return;
     }
 
     HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(IDD_INDIRECT),
          RT_DIALOG);
     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),
                             RT_DLGINIT);
     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);  
     dlg.DoModal();    
 
     ::UnlockResource(hTemplate);
     ::FreeResource(hTemplate);
     if (hDlgInit)
     {
          ::UnlockResource(hDlgInit);  
          ::FreeResource(hDlgInit);
     }    
}
<MSDN>
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
hi bachar,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
Comment Utility
hi bachar,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
bachar,

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.
http://experts-exchange.com/jsp/qShow.jsp?ta=progsoftgen&qid=20186509
http://experts-exchange.com/jsp/qShow.jsp?ta=progsoftgen&qid=20100277
http://experts-exchange.com/jsp/qShow.jsp?ta=progsoftgen&qid=20005648
http://experts-exchange.com/jsp/qShow.jsp?ta=progsoftgen&qid=11452298
http://experts-exchange.com/jsp/qShow.jsp?ta=progsoftgen&qid=11404058
http://experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20141685
http://experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20093290
http://experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=20145151
http://experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=20116236
http://experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=20094685
http://experts-exchange.com/jsp/qShow.jsp?ta=networkgen&qid=20032846

EXPERTS: Please leave your thoughts on this question here.

Thanks,

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
Admin notified of user neglect. Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 83
Separate files macro - Errors on larger data set 18 56
if loop in java 3 114
centeredAverage challenge 8 120
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now