在运行时加载一个COM DLL? [英] Load a COM dll at runtime?

查看:121
本文介绍了在运行时加载一个COM DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了桃树AP​​I的应用程序,它需要与任何版本的API的工作。不幸的是,从桃树2011的DLL不能与桃树2010,反之亦然互动,即使这两个dll文件都存储在同一个位置,用完全相同的code运行。

I'm writing an application for the Peachtree API and it needs to work with any version of the API. Unfortunately the dll from Peachtree 2011 can't interact with Peachtree 2010, and vice versa, even though the two dlls are stored in the same location and run with exactly the same code.

我想我应该能够引用的DLL由它的文件路径,留下具体的版本错误,嵌入互操作类型的错误,并复制本地的假的,它只是使用任何版本的机器了,但我得到当我做了一个错误 - 异常被抛出调用的目标。

I thought I should be able to refer to the dll by it's file path, leave specific version at false, embed interop types at false, and copy local at false and it would just use whatever version the machine had, but I get an error when I do that - "Exception has been thrown by the target of an invocation."

有没有办法来晚绑定,即使它是COM的DLL?

Is there a way to late-bind the dll even though it's COM?

我能提供什么,你认为将是有益的code样品,但它更多的是项目设置的问题比什么都重要的。

I can provide code samples of whatever you think would be helpful, but it's more of a project setup issue than anything.

编辑:谢谢大家非常的帮助。我发现我在不同的人的问题的解决,并张贴在这里。

Thank you all very much for your help. I found my solution on a different person's question and posted it here.

推荐答案

后期绑定到COM对象要求您没有添加引用COM库到你的.NET项目。相反,你应该使用这样的事情来创建COM对象:

Late-binding to COM objects requires that you do NOT add a reference to the COM library to your .NET project. Instead, you should you use something like this to create COM objects:

   Type type = Type.GetTypeFromProgID("Excel.Application")
   object app = Activator.CreateInstance(type);

然后,它会绑定在运行时任何版本的COM库。

Then, it will bind to any version of the COM library at runtime.

请参阅<一href="http://www.c-sharpcorner.com/UploadFile/psingh/CallingCOMComponentFromCSharp12022005231615PM/CallingCOMComponentFromCSharp.aspx">this文章更多细节。

这篇关于在运行时加载一个COM DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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