0

我有一个 .NET 类,它公开了两种公共方法:一种用于创建 InfoPath 表单,另一种用于导出为一种受支持的格式。我正在使用 Microsoft FormControl 来执行此操作。它由不显示的表单托管。我被 Winforms 应用程序调用,但在 MTA 工作线程而不是 UI 线程上调用。所以我创建了一个 STA 线程并在其上执行,它只工作一次,然后导致这个异常:

System.InvalidOperationException 未处理 Message="无法获取 'FormControl' 控件的窗口句柄。不支持无窗口 ActiveX 控件。" Source="System.Windows.Forms" StackTrace:在 System.Windows.Forms.AxHost.InPlaceActivate() 在 System.Windows.Forms.AxHost.TransitionUpTo(Int32 state) 在 System.Windows.Forms.AxHost.EnsureWindowPresent() System.Windows.Forms.AxHost.CreateHandle() 在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 在 System.Windows.Forms.AxHost.EndInit( ) 在 C:\Windows\Temp\InfoPathCreateStaThreadTest\InfoPathCreateStaThreadTest\FormControlHost.Designer.cs 中的 InfoPathCreateStaThreadTest.FormControlHost.InitializeComponent():

经过一些试验,我开始怀疑这是一个消息泵送问题。然后我遇到了这个,这让我更加怀疑:http: //blogs.msdn.com/cbrumme/archive/2004/02/02/66219.aspx

我尝试了各种发送消息的方法,但都没有成功。我应该提到自动化 InfoPath 应用程序的替代方案是不可行的,除非我能弄清楚如何隐藏该应用程序。

任何帮助将非常感激。

4

3 回答 3

1

您是否在加载表单创建工作线程(调用控件的线程) ?在我将所有调用移至父窗体的 Load 事件中的 FormControl 之前,我一直遇到这个问题。自从这样做以来,我没有遇到过这个特定的错误(尽管我见过很多其他错误)

于 2011-02-15T16:11:29.517 回答
0

Thanks for your reply. Sorry for the long delayed reply on my end. DEP is not causing the problem for me. I ended up automating the InfoPath app vs. using the FormControl. Best of luck getting your issue resolved!

Rob

于 2009-04-05T05:47:49.520 回答
0

我正在研究同样的错误并发现:http ://social.msdn.microsoft.com/Forums/en-US/clr/thread/9c36e5d3-a75c-4760-9070-5dbaf188992b/将问题归因于 DEP意外打开并提供了修复。我还不知道这是否能解决我的问题。

于 2009-02-27T16:43:28.370 回答