Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the interop 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.

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

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

like image 351
Prabu Avatar asked Nov 03 '09 23:11

Prabu


People also ask

What is an Interop C#?

Interoperability (C# Programming Guide) Interoperability enables you to preserve and take advantage of existing investments in unmanaged code. Code that runs under the control of the common language runtime (CLR) is called managed code, and code that runs outside the CLR is called unmanaged code.

What is COM DLL in C#?

A Dynamic Link library (DLL) is a library that contains functions and codes that can be used by more than one program at a time. Once we have created a DLL file, we can use it in many applications. The only thing we need to do is to add the reference/import the DLL File.

Do we need to register Interop DLL?

Although it is not necessary to register primary interop assemblies unless you plan to use Visual Studio, registration provides two advantages: A registered primary interop assembly is clearly marked under the registry key of the original type library.

How do I create an Interop DLL?

To generate an interop assembly from a type libraryAdding the /out: switch produces an interop assembly with an altered name, such as LOANLib. dll. Altering the interop assembly name can help distinguish it from the original COM DLL and prevent problems that can occur from having duplicate names.


1 Answers

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.

(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.)

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.

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.

like image 79
Pavel Minaev Avatar answered Nov 10 '22 01:11

Pavel Minaev