AxHost.AttachInterfaces 方法


在派生类中替代时,将接口附加至基础 ActiveX 控件。When overridden in a derived class, attaches interfaces to the underlying ActiveX control.

 virtual void AttachInterfaces();
protected virtual void AttachInterfaces ();
abstract member AttachInterfaces : unit -> unit
override this.AttachInterfaces : unit -> unit
Protected Overridable Sub AttachInterfaces ()


下面的代码示例将重写构造函数, SetAboutBoxDelegate以及AttachInterfaces包装 Microsoft 掩码AxHost编辑 ActiveX 控件的派生类的和方法。The following code example overrides the constructor, and the SetAboutBoxDelegate and AttachInterfaces methods of an AxHost derived class that wraps the Microsoft Masked Edit ActiveX Control. 此代码要求你已创建生成的源代码,方法是在 MSMask32 文件上运行 aximp.exe,并使用/source开关生成要编辑的包装类。This code requires that 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. 此代码仅在语法中C#显示,因为这是 aximp.exe 所输出的唯一语言。This code is only shown in C# syntax because that is the only language output by the AxImp.exe.

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)

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


扩展AxHost的类应重写此方法。Classes that extend AxHost should override this method. 在此方法的重写版本中,扩展类应调用GetOcx()来检索其自己的接口。Within an overridden version of this method, the extending class should call GetOcx() to retrieve its own interface. 在大多数情况下, GetOcx()不应在调用此方法之前调用方法。In most cases, the GetOcx() method should not be called before this method is called.