Can a managed ref-class directly implement a COM interface?

匆匆过客 提交于 2019-12-07 09:49:26

I just got curious about this topic and played around and I found out some minor differences:

I have IVI-COM class library on my PC, and always wanted to try to interface some of them, although the IVI also has .Net interfaces so it does not make too much sense...

I started with C#, where we get good IntelliSense support. I have added the necessary references and added a class to my project. With the object browser we can select an interface.

public class MyDmm : IIviDmmMultiPoint
{
}

After that just use IntelliSense (Ctrl-.) to add the ‘using’ statement and let them make the necessary properties and methods for us.

using Ivi.Dmm.Interop;
///...
public int Count
{
    get
    {
        throw new NotImplementedException();
    }
///...

So now we need the C++-CLI dialect :) Which is as follows:

using namespace IviDmmLib;
///...
public ref class Dmm : IIviDmmMultiPoint
{

Note that the name used by the using statement is different, we can obtain this by selecting the reference at the Solution Explorer and check the name shown at the ‘Properties’ below.

I did not fully complete the experiment but I saw that the COM library was x64 bit, so we may compile the project for the same.

Further interesting readings:

Please, give me feedback if you find some more differences, so we can put them here too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!