ActiveX控件没有形式 [英] ActiveX control without a form

查看:163
本文介绍了ActiveX控件没有形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要使用第三方ActiveX控件。

We are required to use a 3rd party ActiveX control.

唯一的问题是,在我们的软件层是业务层,并有一个窗口进不去或形式。它还可以运行在单独的线程(而且应该从任何线程工作)不属于STA。

The only issue is, the layer in our software is a business layer and has no access to a window or form. It also runs on separate threads (and should work from any thread) that are not STA.

而不是从业务逻辑中打破了我们的用户界面的分离,我们使用这个解决方法使其工作:

Rather than breaking our separation of UI from business logic, we used this workaround to make it work:

Thread thread = new Thread((ThreadStart)
delegate
{
_myActiveX = new MyActiveXType();
_myActiveX.CreateControl();

//more initialize work

Application.Run();
});
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Start();



然后我们随时需要引用的控制,我们称之为 _myActiveX.BeginInvoke( )的invoke()

在这个类的处置(退出我们的应用程序),我们处理的控制并中止线程。

On disposing of this class (exiting our app), we dispose the control and abort the thread.

我的问题是,是否有任何与此问题?有没有更好的方式来处理呢?

My question is, are there any problems with this? Is there a better way to handle this?

有没有更好的内置的方式从一个未知的多线程环境中使用ActiveX控件来工作?我们正在尝试写我们在一个包装的控制,但会从任何线程的工作方式类

Is there a better built in way to work with an ActiveX control from within an unknown multi-threaded environment? We are trying to write our class in a way that wraps the control but will work from any thread.

更​​新:作为一个答案的建议,我们真的宁愿使用标准COM对象,而不是使用控制在所有。我们与问题是我们会得到错误(从HRESULT异常:0x8000FFFF(E_UNEXPECTED)。在第一方法或属性,我们调用COM对象上这是使用ActiveX的时候,我们没有得到一个漂亮的一般错误,任何想法

UPDATE: As an answer suggested, we really would rather use the standard COM object and not use a control at all. Our issue with that was we would get the error "(Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)" upon the first method or property we call on the COM object. This is a pretty generic error that we don't get when using the ActiveX, any ideas?

更新:?我们的OCX是CX25.ocx,采用tlbimp.exe是我们得到CX25Lib.dll使用aximp.exe,我们得到AxCX25Lib.dll和CX25Lib.dll。CX25Lib.dll不会在任何情况下工作。AxCX25Lib.dll工作。

UPDATE: Our ocx is "CX25.ocx", using tlbimp.exe we get CX25Lib.dll. Using aximp.exe, we get AxCX25Lib.dll and CX25Lib.dll. CX25Lib.dll does not work in either case. AxCX25Lib.dll works.

推荐答案

我假设这是去对此的正确方法。

I'm assuming this is the proper way to go about this.

我们一直在使用我上面的代码在测试环境中对没有问题,过去几个星期。

We've been using my code above in test environments for the past few weeks with no issues.

如果任何人有使用ActiveX没有一个形式,我认为这是做这件事。

If anyone has to use an ActiveX without a form, I assume this is one way to do it.

只要确保调用_yourActiveXControl.CreateControl()后直接您的ActiveX对象的构造函数,这简化了我们原来有很多的问题。

Just make sure to call _yourActiveXControl.CreateControl() directly after your ActiveX object's constructor. This simplified many issues we had originally.

这篇关于ActiveX控件没有形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆