can any interface inheriting IUnknown be made into a COM interface?

可紊 提交于 2019-12-11 15:54:12

问题


I need to call methods of the IWeatherStation interface which inherits IUnknown from C#. How do I go about it, if it is possible?

Thank you


回答1:


Sure. There is an example here: Example COM Class (C# Programming Guide).

The first thing you should do is locate the real (idl or c/c++) definition of the interface. For this SDK it's located for example in the <setup path>\Lockheed Martin\Prepar3D v4 SDK 4.3.29.25520\inc\PDK\IWeatherSystem.h header file. This is where you will get the methods and the interface id (a.k.a. 'IID').

So in your case, it would be something like:

[Guid("e4452b96-16ba-4e82-9342-aa37af1f5c26")] // IID
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IWeatherStationV430 // IUnknown base interface is implicit
{
    bool IsValid();
    float GetSurfaceWind();
    void SetSurfaceWind(float aVal);
    // etc...
}


来源:https://stackoverflow.com/questions/52425122/can-any-interface-inheriting-iunknown-be-made-into-a-com-interface

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