Using a COM dll from C# without a type library

前端 未结 7 2187
梦谈多话
梦谈多话 2020-12-14 12:23

I need to use a COM component (a dll) developed in Delphi ages ago. The problem is: the dll does not contain a type library... and every interop feature (eg. TlbImp) in .NET

7条回答
  •  悲&欢浪女
    2020-12-14 13:07

    It is quite frequent that you will encounter an interface implementation that is not backed by a type library (Delphi or otherwise). Shell extensions are one example.

    You basically need to make a Windows API call to create the instance through the proper COM function calls. The API will take care of managing the DLL via the exported functions you mentioned earlier.

    You will need to recreate the interface definition in C# code but after that you simply create the object, cast it to the interface, and it is no different than anything else. The only real caveat here is, depending on your usage, you may have some threading issues to deal with so check the "threading model" that was used for the DLL and consider your usage based on that.

    Here is a link to a tutorial on consuming the interfaces that are not TLB based. Tutorial

提交回复
热议问题