English 中文(简体)
在从多翻新公寓获得翻新型公寓的公交车
原标题:Error when accessing a COM dll with Threading Model Apartment from Multithread Apartment

I have to communicate with a third party application and the only way to do so is by accessing the provided COM component. Because the interaction takes about 3 minutes it s mandatory that it takes place in the background. So what i tried to do is to add a reference the component with option "embedd interop-types" = true and to create a test that reads very basic data through the interface. The documented way to do so is by following Code:

System sys = new System();
if(Convert.ToBoolean(sys.Initialize()) && Convert.ToBoolean(sys.Login("John Smith", out userInstance)))
Project proj = new Project();
if (Convert.ToBoolean(proj.Open(sys, m_projName, m_scenarioName)))
    someValue = proj.Name;

这一工作完全持续到背景工作者使用为止。 接着,我对第一行的法典有以下错误:

无法投放系统类型的COM物体。 这项行动之所以失败,是因为Query Interface呼吁COM部分参与国际交易日志的接口(1F5EB3E2-35F6-11D2-A191-0060083A260B}由于以下错误而失败:超负荷型图书馆/DLL。 (摘自HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRaire))。

我已尝试在没有任何成功的情况下重新修补该构成部分。

When using the BackgroundWorker the Thread Apartment Type obviously is MTA. The COM component has ThreadingModel set to apartment. If I understood this article http://msdn.microsoft.com/en-us/library/eaw10et3.aspx correctly the interop marshalling should take care of accessing the Objects.

没有人会想做些什么?

最佳回答

所发生的情况是,马歇尔无法将物体释放。

www.un.org/spanish/ecosoc 第一回答: 标准游艇需要一个类型的图书馆。 也许物体类型图书馆没有正确登记,因此错误。 您是否在X86或x64上? 在REGTLB注册图书馆。

www.un.org/spanish/ecosoc 第二次回答: 如果这种工作不可行,便捷的答案是使用STA式公寓。 这可能意味着你不能使用背景工作者,但可能不得不使用你在完成后销毁的专用线。 如果我们谈论一个三分钟的行动,则额外间接费用微不足道。

说明必须在使用该物体的深层上制造该物体,而公寓类型则与物体翻新模型相容,以避免发生摩擦。

问题回答

您不能使用背景工作者,其面貌是错误的。 可以改变的是,它使用透水池,而且总是使用MATA。 COM公司自动创建了一个STA,为COM服务器提供可观的住所,这将引发任何打碎的电话。 该部门无法运作,因此没有适当登记其类型的图书馆。 有些人想避免任何进展。

You must create your own Thread instead and call its SetApartmentState() method to switch it to to STA before you start it. It is also important that you create the instance of the COM object on that thread, otherwise the CLR will still try to marshal the calls. Technically you need to pump a message loop (Application.Run) but you might get away with not needing to do so. You ll find out, if a call deadlocks or an expected event doesn t fire then the message loop is required.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签