什么是互操作的dll? [英] What is the interop dll?

查看:115
本文介绍了什么是互操作的dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些澄清。我有一个使用Crystal Reports中Reportwriter DLL。这是写在VB6。我必须把这个DLL添加到我的asp.net项目,它创建了一个互操作的DLL。

I need some clarification. I have a Reportwriter dll that uses Crystal Reports. It is written in VB6. I have to add this dll to my asp.net project, where it creates an interop dll.

据我了解,互操作的dll有作为中间人让自己的.NET code,可向Reportwriter DLL说话。

To my understanding, the interop dll is there as an intermediary so that my .net code can speak to the Reportwriter dll.

所以我注册DLL互操作或做我注册原始的dll文件?

So do I register the interop dll or do I register the original dll?

推荐答案

当你写在VB6 code,编译后的结果是一个COM组件。 COM组件提供的接口,组件类,结构和枚举,它使用的是COM类型库通常描述。然而,消耗了.NET COM组件,你需要在.NET理解的格式类型说明 - 即一个.NET程序集(因为它不能与类型库直接工作)。因此,一个互操作程序集只是一个转换COM类型库,在某种意义上说,它包含了对应于同样的事情在类型库接口,结构等的说明。

When you write code in VB6, the compiled result is a COM component. COM components provide interfaces, coclasses, structs and enums, which are normally described using a COM type library. However, to consume that COM component in .NET, you need type description in a format that .NET understands - that is, a .NET assembly (since it cannot work with type libraries directly). An interop assembly is therefore just a "converted" COM type library, in a sense that it contains descriptions of interfaces, structs etc that correspond to the same things in a type library.

(以上有所简化,因为互操作程序集不的有无的是从一个类型库产生的 - 你可以手工code之一,如果你想,例如)

(The above is somewhat simplified, as interop assembly doesn't have to be produced from a type library - you can hand-code one if you want, for example.)

相反的是常说,互操作程序集不包含任何可执行code,它没有做任何编组。它仅包含类型的定义,并且其中它可以具有方法的唯一位置是在接口和接口中的方法没有实现。封送.NET调用COM那些实际上是由CLR本身基于从互操作程序集装式的描述做了 - 它产生的飞行一切必要的code

Contrary to what is often said, an interop assembly doesn't contain any executable code, and it doesn't do any marshalling. It only contains type definitions, and the only place where it can have methods is in interfaces, and methods in interfaces don't have an implementation. Marshaling .NET calls to COM ones is actually done by CLR itself based on type descriptions loaded from interop assemblies - it generates all necessary code on the fly.

现在以你的问题。您需要注册您的COM DLL项目(您的VB6的输出) - 例如,使用的regsvr32.exe 。你不应该(其实你不能)注册一个互操作程序集的方式,因为它不是一个COM组件 - 它只是一个普通的.NET程序集,所以你可以把它放在同一个文件夹与您的.exe / .dll ,或者把它放进GAC,像往常一样。

Now as to your question. You need to register your COM DLL (the output of your VB6) project - for example, using regsvr32.exe. You shouldn't (in fact, you cannot) register an interop assembly that way, because it's not a COM component - it's just a plain .NET assembly, so you can either put it in the same folder with your .exe/.dll, or put it into GAC, as usual.

这篇关于什么是互操作的dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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