android中IBind,c# - 如何在C#中声明经典COM接口IBindCtx? - 堆栈内存溢出

我目前在C#和COM接口周围闲逛。 C#中的COM文档很少,因为C#紧随COM之后(也许我们可以解决)。 可以从错误消息中读取方法签名的C#语法版本,然后将其添加到您的类中。 这适用于IAdviseSink,但不适用于IBindCtx。

我对最后一个方法RevokeObjectParam(string a)遇到错误,C ++中的语法为HRESULT RevokeObjectParam( [in] LPOLESTR pszKey ); 且LPOLESTR是一个以2 LPOLESTR的以null终止的字符串,因此可以使用[MarshalAs(UnmanagedType.LPWStr)] 。 但是没有,我收到错误消息

* Class1.cs(25,14,25,40): error CS0539: 'IBindCtx.RevokeObjectParam' in explicit interface declaration is not a member of interface

* Class1.cs(6,18,6,24): error CS0535: 'ComInterfacesInCSharp.Class1' does not implement interface member 'System.Runtime.InteropServices.ComTypes.IBindCtx.RevokeObjectParam(string)'

那么,如何修改此方法签名以进行修复? 下面是可复制到Visual Studio中的完整代码(创建类库项目)。

using System.Runtime.InteropServices.ComTypes;

using System.Runtime.InteropServices;

namespace ComInterfacesInCSharp

{

public class Class1 : System.Runtime.InteropServices.ComTypes.IBindCtx

{

void IBindCtx.RegisterObjectBound(object obj) { }

void IBindCtx.RevokeObjectBound(object obj) { }

void IBindCtx.ReleaseBoundObjects() { }

void IBindCtx.SetBindOptions(ref System.Runtime.InteropServices.ComTypes.BIND_OPTS opts) { }

void IBindCtx.GetBindOptions(ref System.Runtime.InteropServices.ComTypes.BIND_OPTS opts) { }

void IBindCtx.GetRunningObjectTable(out System.Runtime.InteropServices.ComTypes.IRunningObjectTable tab) { }

void IBindCtx.RegisterObjectParam(string s, object obj) { }

void IBindCtx.GetObjectParam(string s, out object obj) { }

void IBindCtx.EnumObjectParam(out System.Runtime.InteropServices.ComTypes.IEnumString enumString) { }

/* Problem here https://msdn.microsoft.com/en-us/library/windows/desktop/ms693771(v=vs.85).aspx

* C++ Syntax is

* HRESULT RevokeObjectParam( [in] LPOLESTR pszKey );

* LPOLESTR is a null terminated 2 byte based string so UnmanagedType.LPWStr ought to work

*

*/

//void IBindCtx.RevokeObjectParam(string a) { }

void IBindCtx.RevokeObjectParam([MarshalAs(UnmanagedType.LPWStr)] string a) { }

/*

* Compile errors are

* Class1.cs(25,14,25,40): error CS0539: 'IBindCtx.RevokeObjectParam' in explicit interface declaration is not a member of interface

* Class1.cs(6,18,6,24): error CS0535: 'ComInterfacesInCSharp.Class1' does not implement interface member 'System.Runtime.InteropServices.ComTypes.IBindCtx.RevokeObjectParam(string)'

*/

}

}

顺便说一句,如果您有一个Web资源详细介绍了C#中的这些接口,那真是太棒了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值