Expose C# class through COM Interop

后端 未结 1 578
悲&欢浪女
悲&欢浪女 2020-12-21 22:20

I have a C# class library and also have a powerbuilder application. I want to expose the c# class and use it in the powerbuilder application. I used the following blogs to e

相关标签:
1条回答
  • 2020-12-21 23:03
     [ClassInterface(ClassInterfaceType.None)]
    

    That means that none of the class implementation details are visible, the proper and pure COM way. So it is not necessary to apply [ComVisible(false)] on methods you don't want to expose. Only the Iinterface methods are visible.

    Using, say, ClassInterfaceType.AutoDual is a convenience in .NET, the CLR will synthesize an interface automatically. It matches the behavior of old versions of Visual Basic (VBA, VB6), they did not support interfaces yet. It does however expose too much, the methods inherited from System.Object (like GetHashCode etc) will be visible as well without a decent way to hide them. You also get a dependency on the mscorlib.tlb type library. So declaring the interface explicitly like you did is the certainly better way.

    The target machine must have .NET installed, rock-hard requirement.

    0 讨论(0)
提交回复
热议问题