MFC Activex Control - Failed to create control: Unspecified error

Hello,

I have created an activex control in MFC 8, VS - 2005 Beta 2, which hosts Windows Forms control in it. I have created it as per the article by Nicola (MFC 8 (VC++ 2005 and Windows Forms). When I test using the activex tester I get the message - Failed to create control: Unspecified error. When I refered this object in a html page using the object tag - It does not show the object. I have used the /clr option.

I noticed one more thing - When I comment out CWinFormsControl related code, the activex object displays on the html page. When I add the CWinformsControl code back, it does not even go into the OnInitDialog method of the activex control.

I am at a dead end here and any help on this subject will be appreciated.

Thanks,

[753 byte] By [MadhuK] at [2007-12-16]
# 1
Hi,

I am glad to hear you found my article usefull. :-) Now let's try fix this problem. Your control is another Dll, isn't it? Is that Dll is next to MFC ActiveX control (same directory) when you test this control? Try opening Event Viewer (type eventvwr in Command Prompt, http://support.microsoft.com/default.aspx?scid=kb;en-us;308427&sd=tech) and see what event is fired for your application when it is loaded.

Thanks,
Nikola

NikolaDudar at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2

Hi Nikola!!!!
Thanks for your response. Originally i was having trouble displaying an activex control compiled with /CLR option. This got fixed after i installed VS 2005 CTP July 2005.

Now I have run into another problem. I have created a simple button control in .Net, just like what you did in your example. and an MFC ACtivex control is hosting it. I implemented the MFC activex control exactly like yours. The programme is erroring on the statement :

m_MyUc.CreateManagedControl(SW_SHOW, IDC_STATIC1,
this);

Application popup: IEXPLORE.EXE - Application Error : The instruction at "0x0b1df88a" referenced memory at "0x00000000". The memory could not be "read".

When I do a cancel to debug - it is pointing to occcont.cpp

BOOL CWnd::InitControlContainer(BOOL bCreateFromResource)

Also I am not able to debug my MFC code.

I would be very glad if you could give me pointers.!!!!

Thanks again.

Madhu K.

MadhuK at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 3
Hi,
Forgot to mention, .net dll is in the Debug folder of the Activex Control. I also created a typelib for the .net dll using regasm and ran Gacutil.

Thanks
Madhu

MadhuK at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 4
occcont.cpp is not a file that is part of MFC, it is most likely a bug in your code. You may not be able to debug because you need to specify Mixed Debugging in Project Properties. Could you please do one of two things. Either open a bug with a small repro project on lab.msdn.microsoft.com or send a zip with project to me directly nikolad on microsoft com.

Thanks,
Nikola
The tracking bug for this issue is

http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=644d8546-20a4-4c3a-854d-834b04afb1fe

Please refer to this link for futher information.

Nikola

NikolaDudar at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 5
"I have created it as per the article by Nicola (MFC 8 (VC++ 2005 and Windows Forms)"
Where can I find this article? I found Nicola's sample on MSDN, but I cannot find the article.
Natasa
N.Soltic at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 6

N. Soltic wrote:
"I have created it as per the article by Nicola (MFC 8 (VC++ 2005 and Windows Forms)"

Where can I find this article? I found Nicola's sample on MSDN, but I cannot find the article.

Natasa

I think the OP meant this blog entry :

http://blogs.msdn.com/nikolad/archive/2005/07/19/440542.aspx

You can also read an article I wrote which is a step by step guide on using a Windows Forms control in an MFC dialog :-

http://www.codeproject.com/managedcpp/mfcdialogwinforms.asp

NishantSivakumar at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 7
Thanks for that!
I am trying to wrap a .Net controls as an MFC Active X with VS 2005, but I really dont know where to start... I have looked at Nicola's sample, but I do not know what parts will be useful to me. Any hints?
N.Soltic at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 8

I am not sure what exactly you are trying to do. Do you already have MFC ActiveX control and you are trying to replace part of its UI with a WinForm control? I remember I looked into this scenario at some point and find it not possible to implement. Sorry I do not remember details.

If you are looking for a general way of wrapping Windows Form control as an ActiveX control, this task has nothing to do with MFC. It is general Winform/COM interop issue. Quickly searching web, I have found this example of doing this http://www.codeproject.com/cs/miscctrl/exposingdotnetcontrols.asp. I think it is the same to what you are trying to do.

Nikola

NikolaDudar at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 9
Hi,
I too have same problem. Failed to create control: Unspecified error.
Actually i registered my dll in ActiveX control Test container in the menu Registar Controls.
PleaSE tell me how to create the control. It is very urgent.

Thanks
Gugapriya Jagadeesan

GugapriyaJagadeesan at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 10

When I select Common Language Runtime Support for this thing to work.

[code]
#using <System.dll>
#using <System.Security.dll>
[/code]

However it works in Normal dialog Based and SDI/MDI Applications. But in an ActiveX control it generates these warning.

[code]
c:\Adeel\Projects\Automation\DigitalCertificate\DigitalCertificateCtrl.cpp : warning C4793: 'virtual-call thunks are native with /clr' : causes native code generation for function 'COleControl::`vcall'{492}''
c:\Adeel\Projects\Automation\DigitalCertificate\DigitalCertificateCtrl.cpp : warning C4793: 'virtual-call thunks are native with /clr' : causes native code generation for function 'COleControl::`vcall'{496}''
Compiling resources...
Linking...
Creating library C:\Adeel\Projects\Automation\DigitalCertificate\Debug\DigitalCertificate.lib and object C:\Adeel\Projects\Automation\DigitalCertificate\Debug\DigitalCertificate.exp
mfcm80ud.lib(postrawdllmain.obj) : warning LNK4099: PDB 'mfcm80ud.i386.pdb' was not found with 'c:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfcm80ud.lib' or at 'c:\Adeel\Projects\Automation\DigitalCertificate\Debug\mfcm80ud.i386.pdb'; linking object as if no debug info
mfcm80ud.lib(postdllmain.obj) : warning LNK4099: PDB 'mfcm80ud.i386.pdb' was not found with 'c:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfcm80ud.lib' or at 'c:\Adeel\Projects\Automation\DigitalCertificate\Debug\mfcm80ud.i386.pdb'; linking object as if no debug info
[/code]

As a result the control does'nt get loaded in OLE container or ActiveX test container. It generates error. Can someone help me with this?

maverick786us at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...