How to set the OcxState of the activeX control in WPF application (Urgent).

Posted by Anwarcode under WPF on 2/14/2010 | Views : 12797 | Status : [Member] | Replies : 3
Hi,
How to set the OcxState of the activeX control in WPF application. I am using third party component (ActiveX Control) in WPF. While loading the source to the control it is throwing exception InvalidActiveXStateException occurred {"Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown."}.
I following code throws the exception

usercontrol = (DynamicPdfViewer)obj;
usercontrol._pdfDocument.OpenStream((Stream)e.NewValue,"");

I googled it and it was suggested that when the control is not properly initialized then this exception occurs. I tried initializing the component by setting the OcxState

this._pdfDocument.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("_pdfDocument.OcxState")));

but this too is throwing an exception. MissingManifestResourceException occurred {"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure \"ceTe.DynamicPDF.AxViewer.DynamicPDFViewer.resources\" was correctly embedded or linked into assembly \"ceTe.DynamicPDF.AxViewer\" at compile time, or that all the satellite assemblies required are loadable and fully signed."}

Put some light on it as soon as possible

Regards,
Anwar




Responses

Posted by: Abhi2434 on: 2/14/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Tell me where you are loading your control?

I think you cant load a windows Control into a WPF window. You need to use WindowsFormsHost to be able to host any ActiveX.

Add this namespace in windows :
xmlns:formsInt="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"


Now use
<formsInt:WindowsFormsHost Width="250" Height="150">

// add your activex control here
</formsInt:WindowsFormsHost>


I hope this would help you.



www.abhisheksur.com

Anwarcode, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anwarcode on: 2/14/2010 [Member] Starter

Up
0
Down
Thanks Abhi,

I am hosting the control in the WindowsFormsHost using the WPF user control as you have mentioned. But in the code behind I am creating a private variable _pdfDocument of type the thrid party control [DynamicPDF4Net]. But when I access the method listed in the _pdfDocument an exception is thrown

usercontrol = (DynamicPdfViewer)obj;
usercontrol._pdfDocument.OpenStream((Stream)e.NewValue,"");

InvalidActiveXStateException occurred {"Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown."}.

To resolve this, as there may be chances that control is not properly initialized. I have added the following code for initilization, but again it is throwing OcxState exception
The code snipped is as below

public partial class DynamicPdfViewer : UserControl
{
#region [ Private Variables ]

ceTe.DynamicPDF.AxViewer.Control.DynamicPDFViewerControl _pdfDocument = new DynamicPDFViewerControl();

#endregion

#region [ Constructor ]

public DynamicPdfViewer()
{

InitializeComponent();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DynamicPDFViewer));
((System.ComponentModel.ISupportInitialize)(this._pdfDocument)).BeginInit();
_pdfDocument.SuspendLayout();
_pdfDocument.Dock = System.Windows.Forms.DockStyle.Fill;
_pdfDocument.Enabled = true;
_pdfDocument.Location = new System.Drawing.Point(0, 0);
_pdfDocument.Name = "pdfViewer";
this._pdfDocument.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("this._pdfDocument.OcxState")));
_pdfDocument.Size = new System.Drawing.Size(337, 359);
_pdfDocument.Text = "_pdfDocument";
//_pdfDocument.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("_pdfDocument.OcxState")));
_pdfDocument = new ceTe.DynamicPDF.AxViewer.Control.DynamicPDFViewerControl();
((System.ComponentModel.ISupportInitialize)(this._pdfDocument)).BeginInit();
}







Anwarcode, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/14/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
If manifest is missing, I think you have to create a manifest for it. Might be it requires certain permission which is not present with it.

Yes, InvalidActiveXStateException occurs when a COM object is not initialized properly. Might be the reference of controls that it is internally invoking when you are invoking OpenStream is not correctly initialized, and hence it throws this exception.

I think you may write to the forum of PDF4net directly. They would have a better idea on what exactly you require to do.

I am also sure you will find a few in their forum who found the same issue before you.

As I didnt used it personally, I cant give you the exact scenario. May be somebody else here can.

Cheers
:)

www.abhisheksur.com

Anwarcode, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response