【发布时间】:2013-06-29 05:56:34
【问题描述】:
我有一个返回类型为字符串(甚至是对象)的属性,它在 .tlh 文件中作为 get_Name 和 put_Name 暴露在 COm 中。如何在非托管 c++ 中访问并设置此属性。 直到现在.. 在 C# 方面, 我通过具有 DispId(1) 的接口公开了此属性,并在继承该接口的类中实现了它。 在 C++(非托管端)中, 我使用以下语法创建了一个接口指针:
ManagedDLL::ICalculatorPtr pICalculator;//Interface having the property
hr = pICalculator.CreateInstance(__uuidof(ManagedDLL::Calculator));//1. Calculator implements property of Icalculator & hr is of HRESULT type
pICalculator->put_Name="New1";
pICalculator->put_Name="New2";//below error comes here :
错误 C2659:“=”:作为左操作数起作用 我知道这个错误的含义。 仅供参考:当我的 Name 属性在非托管 c++ 中设置时,我想在 c# 中引发一个事件。
【问题讨论】:
标签: c# c++ properties com interop