抛出了类型’System.Windows.Forms.AxHost + InvalidActiveXStateException’的exception

我的简单项目中出现错误。

这是我的代码:

if (axZKFPEngX1.InitEngine() == 0) { label1.Text = "Connected"; } else { label1.Text = "Connection Failed"; } 

我已经添加了参考组合AxInterop.ZKFPEngXControlInterop.ZKFPEngXControl

在调试时,我单击按钮,会出现警告:

处理了InvalidActiveXStateException。

“类型’System.Windows.Forms.AxHost + InvalidActiveXStateException’的exception被抛出”**

尝试首先从组件中调用CreateControl()

Constantin的答案是满足您的要求,但在这里我想再添加一件事。 如果你想通过所有线程反映这种变化,而不仅仅是通过调用线程(在multithreading场景中),那么使用

 CreateControl(); InitWB(); SkinAllThreads(); 

实际上在multithreading场景中,如果你的皮肤代码在其中一个线程中,那么它可能不会反映其他当前线程的变化,所以此时此代码在其中扮演重要角色。

以下是我提到的一些文件,请参考:

  1. initwb()方法
  2. DirectSkin其他方法
  3. 添加直接皮肤到应用程序