Export (0) Print
Expand All

AxHost.InvalidActiveXStateException Class

The exception that is thrown when the ActiveX control is referenced while in an invalid state.

For a list of all members of this type, see AxHost.InvalidActiveXStateException Members.

System.Object
   System.Exception
      System.Windows.Forms.AxHost.InvalidActiveXStateException

[Visual Basic]
Public Class AxHost.InvalidActiveXStateException
   Inherits Exception
[C#]
public class AxHost.InvalidActiveXStateException : Exception
[C++]
public __gc class AxHost.InvalidActiveXStateException : public
   Exception
[JScript]
public class AxHost.InvalidActiveXStateException extends Exception

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

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. The member type is one of the AxHost.ActiveXInvokeKind enumerated values.

Example

[C#] The following example overrides the constructor, and the SetAboutBoxDelegate and AttachInterfaces methods of an AxHost derived class that wraps the Microsoft Masked Edit ActiveX Control. This code assumes you have created the generated source code by running the AxImp.exe on the MSMask32.ocx file with the /source switch to generate the wrapper class to be edited. This code is only shown in C# syntax as that is the the only language output by the AxImp.exe.

[C#] 
public AxMaskEdBox() : 
  base("c932ba85-4374-101b-a56c-00aa003668dc") // The ActiveX control's class identifier.
{
   // Make the AboutBox method the about box delegate.
   this.SetAboutBoxDelegate(new AboutBoxDelegate(AboutBox));
}
        
public virtual void AboutBox() 
{
   // If the instance of the ActiveX control is null when the AboutBox method 
   // is called, raise an InvalidActiveXStateException exception.
   if ((this.ocx == null)) 
   {
      throw new System.Windows.Forms.AxHost.InvalidActiveXStateException(
        "AboutBox", System.Windows.Forms.AxHost.ActiveXInvokeKind.MethodInvoke);
   }
   // Show the about box if the ActiveX control has one.
   if(this.HasAboutBox)
   {
      this.ocx.AboutBox();
   }
}

protected override void AttachInterfaces() 
{
   try 
   {
      // Attach the IMSMask interface to the ActiveX control.
      this.ocx = ((MSMask.IMSMask)(this.GetOcx()));
   }
   catch (System.Exception ex) 
   {
      System.Console.WriteLine(ex.Message);
   }
}

[Visual Basic, C++, JScript] No example is available for Visual Basic, C++, or JScript. To view a C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

AxHost.InvalidActiveXStateException Members | System.Windows.Forms Namespace | AxHost.ActiveXInvokeKind

Show:
© 2014 Microsoft