How to fire property changed notifications from C#

2019-08-24 20:06发布

I am going crazy on this problem for the past couple of weeks. I have a C# Com object that needs to send property change notifications to a C++ Com object. An equivalent in VB would be using code that looks as follows PropertyChanged "propertyName".

In C++ the equivalent to use the CFirePropNotifyEvent class from ATL.

The C++ COM and VB COM objects do not implement a specialized events interface, so the equivalent are give above.. The C++ COM object that needs to sink the event is based around IPropertyNotifySink, afaik.

What is the equivalent in C#? i have tried:

  1. INotifyPropertyChanged from System.ComponentModel
  2. I implemented IObjectWithSite and tried to cast the site object received in setSite to IPropertyNotifySink.
    1. I cannot find an equivalent for CFirePropNotifyEvent in C++/ATL which is what the C++ code uses..

Please help..

Thanks in Advance..

标签: c# c++ com interop
1条回答
何必那么认真
2楼-- · 2019-08-24 20:23

I don't think there is some automatic gateway between .NET's INotifyPropertyChanged and COM's INotifyPropertySink.

If you want a .NET object to provide COM events, you need to provide an implementation of IConnectionPointContainer in these .NET objects.

IConnectionPointContainer already exists in .NET in the System.Runtime.InteropServices.ComTypes namespace.

查看更多
登录 后发表回答