views:

636

answers:

3

Hi guys,

This might be a bit of stupid question but i need some clarification. I have Reportwriter dll that uses crystals 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 a intermediatary 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?

Cheers.

A: 

You're correct. The interop DLL wraps the calls to the VB6 component and makes them transparent.

When registering the DLLs on the machine you'll be executing the application on, you still have to register the VB6 DLL. The interop DLL will sit your app's bin folder and Marshal the calls out.

Justin Niessner
A: 

You should register your VB6 dll and reference it in your .NET project; that reference will create your Interop.dll

Rubens Farias
+13  A: 

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.

Pavel Minaev
+1: wonderful explanation, ty
Rubens Farias
Thanks Pavel. That was exactly what I was looking for.
pwee167
So how does the interop know where the report dll exists, when the i make calls to its methods from my .NET code? Does the interop translate a key in the registry?
pwee167
+1 Great Answer.
Dusty
When you register your COM component, its location is recorded in registry, and can be retrieved from there if the GUID of component is known. Interop assembly knows GUID for the typelib from which it was generated, and GUIDs for all types within that typelib - they're stored as .NET attributes. The runtime will then use this information to resolve COM component via registry.
Pavel Minaev