Solved

InvalidActiveXStateException accessing OCX

Posted on 2003-10-26
3
7,253 Views
Last Modified: 2012-06-27
I'm trying to use an OCX in a C# Windows Form for the first time.  My problem is that I’m getting an InvalidActiveXStateException.

The OCX is one I wrote a couple years ago in C++.  I'm learning C#.

I used the IDE to import the OCX (adding it to the ToolBox and dropping it on a form).
The Object Browser shows the methods correctly.  That says to me that I imported the OCX successfully.

In the code snippet, I use ellipsis (…) for code that’s irrelvant to this question.

public class Form1 : System.Windows.Forms.Form
{
… (ellipsis)
private AxACQUIRELib.AxAcquire axAcquire1;      // this is the OCX wrapper
… (ellipsis)
public Form1()
{
   InitializeComponent();
   this.axAcquire1 = new AxACQUIRELib.AxAcquire();  // Instantiate the wrapper
   this.axAcquire1.Acquire(… (ellipsis));            // Constructor exported by OCX
… (ellipsis)
The constructor call gets the InvalidActiveXStateException.

Two questions:
1.      What am I doing wrong?
2.      Any good references (books or web pages) ?

Thank you.



0
Comment
Question by:josgood
3 Comments
 
LVL 1

Accepted Solution

by:
kellycoinguy earned 250 total points
Comment Utility
Obviously, this is a reasonable place to start...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsaxhostinvalidactivexstateexceptionmemberstopic.asp

Have you printed out the specific message you are getting like so?

catch (InvalidActiveXStateException ex)
{
   MessageBox.Show("Invalid ActiveX State Exception",ex.Message);
}

Once you see the message, it might give you a clue as to what specifically is going wrong. Then again, it might not. Good luck in any case.

If all you get is:"Run-time exception thrown : InvalidActiveXStateException - Exception of type InvalidActiveXStateException was thrown." then that's probably not terribly helpful.

This is a bit of text I lifted that might be useful:
"The public properties and methods of an ActiveX control can only be referenced after the ActiveX control has been instantiated and initialized completely; otherwise the AxHost.InvalidActiveXStateException exception is thrown. The AxHost.InvalidActiveXStateException exception class contains the name of the member that made the reference and the member type."

I'm afraid that's all I can contribute to this subject. Good luck!!

-Kelly
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to get a file from SqlServer DB 4 28
How to read XML file attributes... 17 39
optimize  c# code 7 48
Pass through dll 2 34
Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

13 Experts available now in Live!

Get 1:1 Help Now