Solved

InvalidActiveXStateException accessing OCX

Posted on 2003-10-26
3
7,260 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
ID: 9625397
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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