Avatar of BasiKobrA
BasiKobrA

asked on 

ActiveX OCXState Initialization in C# without Form

Hello,

Situation : (.NET 1.1, VS2003) I'm creating a C# application which uses a specific ActiveX control (not a web application!). When I use a form and add the ActiveX control the Visual Studio way, everything works fine. But since the control does not provide/need a GUI, I want the application to be able to use it without GUI.
The problem is that I don't know how to initialize the ActiveX control programatically to set in the correct OcxState.

I tried the solution presented here :
https://www.experts-exchange.com/questions/23204692/How-to-set-hidden-ActiveX-PARAM-properties.html

While trying to translate this to C#, the MethodInfo turned out to be null, cause my .NET does not seem to know "System.Windows.Forms.UnsafeNativeMethods.IPropertyBag.Write".
But since I don't need to set Properties, I removed the stuff I believed are unnecessary in my case.

Then end up setting the OcxState of the ActiveX control, but still the first method invocation on the control fails.
Web ComponentsC#

Avatar of undefined
Last Comment
BasiKobrA
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

It sounds like you have an ActiveX control that needs a site in order to work properly.
Avatar of BasiKobrA
BasiKobrA

ASKER

What do you mean by 'a site', a graphical environment ?
Is there a way to verify this ? Or do you have a reference to a more thorough explanation about ActiveX/OcxState initialization ?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

A site is a Form, a web page, or anything that can "host" an ActiveX control.

I don't quite understand what the exception is that you got when you didn't add the ActiveX control to a form.
Avatar of BasiKobrA
BasiKobrA

ASKER

I won't be able to get on my development computer again till tomorow, but it is something like this :
* I create an instance of the activex control and the first method call on that instance fails because the control is not in the 'correct' state.
* When I add it to the form, VS generates some code to 'initialize' the OcxState of the control. This code does some kind of request to the resources resx.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

It would help to have more detail than that.  Working with ActiveX can be tricky, and information is king!!
Avatar of BasiKobrA
BasiKobrA

ASKER

Hello again,
The standard exception trace doesn't seem to provide a lot.

* If I just suppose I can instantiate the ActiveX control as a normal object, I do this :
MyAXClass myAxObject = new MyAxClass();
myAxObject.RandomMethodCall();

This throws an exception :
Cannot perform RandomMethodCall at this time.
Exception of type InvalidActiveXStateException was thrown.

* If I include it in a form via VS, this is the extra code which makes the first 'RandomMethodCall()' succeed :
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MyOverviewControl));
((System.ComponentModel.ISupportInitialize)(this.m_myAxObject)).BeginInit();
this.m_myAxObject.ContainingControl = this;
this.m_myAxObject.Enabled = true;
this.m_myAxObject.Location = new System.Drawing.Point(1024, 48);
this.m_myAxObject.Name = "m_vaxsip";
this.m_myAxObject.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("m_myAxObject.OcxState")));
this.m_myAxObject.Size = new System.Drawing.Size(100, 50);
this.m_myAxObject.TabIndex = 6;
((System.ComponentModel.ISupportInitialize)(this.m_myAxObject)).EndInit();

So, should I conclude from this that it does need a site ?
The method calls I can perform on the object don't produce anything graphical, so I wondered why I would need a Form to  use it...


ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of BasiKobrA
BasiKobrA

ASKER

Great Idea, I'll do that.
Thanks.
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo