Каков interop dll?

Помещение функций или переменных в неназванном пространстве имен удерживает от использования использование static для ограничения их объемом файла.

52
задан oberlies 9 May 2014 в 08:44
поделиться

3 ответа

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.

92
ответ дан 7 November 2019 в 09:19
поделиться

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.

2
ответ дан 7 November 2019 в 09:19
поделиться

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

2
ответ дан 7 November 2019 в 09:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: