Creating ActiveX control in an MFC dialog in a DLL 
Author Message
 Creating ActiveX control in an MFC dialog in a DLL

Hi all,

I have a strange problem whereby I have created an DLL with MFC
statically linked using the VC 6.0 AppWizard, and created a dialog
resource, and a corresponding CDialog wrapper for it. I then added an
ActiveX control (the Macromedia Flash 4 player) to the dialog, prompting
creation of the wrapper for that which I add as a member variable, and
then exported a function which looks like:

__declspec(dllexport) CALLBACK MyFunc()
{
    CMyDialog dlg;
    dlg.DoModal();

Quote:
}

When I create a non-MFC EXE implicitly linked to the above DLL, and call
the function, it is unable to create the control, saying:

CoCreateInstance of OLE control {D27CDB6E-AE6D-11CF-96B8-444553540000}
failed.

Quote:
>>> Result code: 0x800401f0
>>> Is the control is properly registered?

The control is properly registered, as it works in VB & indeed in an MFC
exe.
I have added AfxEnableControlContainer() to the CWinApp::InitInstance()
function.

I suspect the problem may be something to do with state management on
the part of MFC as it works in an EXE, but not in a DLL, but can't
figure out what's going on.

Any help greatly appreciated.

Thanks,

Jon



Tue, 28 May 2002 03:00:00 GMT  
 Creating ActiveX control in an MFC dialog in a DLL

Quote:
>When I create a non-MFC EXE implicitly linked to the above DLL, and call
>the function, it is unable to create the control, saying:

>CoCreateInstance of OLE control {D27CDB6E-AE6D-11CF-96B8-444553540000}
>failed.

Jon,

Here's what I've done to make such things work:

extern "C" __declspec(dllexport) BOOL Pascal ExportedFunction()
{
        AFX_MANAGE_STATE(AfxGetStaticModuleState());

        ::OleInitialize(NULL);

        AfxEnableControlContainer();

        CCalDlg dlg;

        dlg.DoModal();

        ::OleUninitialize();

        return true;

Quote:
}

Dave
--
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.


Wed, 29 May 2002 03:00:00 GMT  
 Creating ActiveX control in an MFC dialog in a DLL
Dave,

You are indeed a godsend.

I had exactly the same problem and your solution worked beautifully.

Thank you.

Kevin



Sun, 02 Jun 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. HELP: activex control in dialog box in mfc user dll (dialog not launching)

2. MFC: CDialog::Create fails if dialog contains an ActiveX control

3. Problems with creating a control in an MFC with activeX dll

4. Problems with creating a control in an MFC with activeX dll

5. COM Dll with MFC Dialog containing an ActiveX Control

6. ActiveX control in MFC .dll Dialog.

7. Using an MFC Extension DLL from an MFC ActiveX Control

8. At what place MFC will create ActiveX control?

9. HOWTO: Dynamically create ActiveX Controls in MFC?

10. At what place MFC will create ActiveX control?

11. How to Change the Name ( DisplayName) of an MFC created ActiveX control

12. Creating ActiveX controls based on MFC classes

 

 
Powered by phpBB® Forum Software