Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在C中声明经典COM接口IBindCtx?_C#_C++_Com_Com Interop_Com Interface - Fatal编程技术网

C# 如何在C中声明经典COM接口IBindCtx?

C# 如何在C中声明经典COM接口IBindCtx?,c#,c++,com,com-interop,com-interface,C#,C++,Com,Com Interop,Com Interface,我目前正在研究C和COM接口。C中的COM文档很少,因为C是在COM之后出现的,也许我们可以修复它。我发现了。可以从错误消息中读取方法签名的C语法版本,然后添加到类中。这适用于IAdviseSink,但不适用于iIndctx 我在最后一个方法中得到错误:ReVoKeObjePARAMStRANG C++中的语法是HPrimeRooKeObjutPARAM[L]LPOLESTR是一个以null结尾的基于2字节的字符串,因此使用[MarshalAsUnmanagedType.LPWStr]应该可以工

我目前正在研究C和COM接口。C中的COM文档很少,因为C是在COM之后出现的,也许我们可以修复它。我发现了。可以从错误消息中读取方法签名的C语法版本,然后添加到类中。这适用于IAdviseSink,但不适用于iIndctx

我在最后一个方法中得到错误:ReVoKeObjePARAMStRANG C++中的语法是HPrimeRooKeObjutPARAM[L]LPOLESTR是一个以null结尾的基于2字节的字符串,因此使用[MarshalAsUnmanagedType.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)'
         */
    }
}
顺便说一句,如果你有一个用C语言详细描述这些接口的web资源,那就太棒了

你提供的链接非常棒!它回答了我的问题,即什么是正确的方法签名。现在我肯定是从微软来的

虽然您可以从中找到许多源代码定义,但它不是查找程序集中定义的方法的签名的唯一选项

学会使用。查看菜单->对象资源管理器或按F2键

在实现接口的特定情况下,可以让Visual Studio为您自动实现接口。右键单击接口名称并选择ImplementInterface


不清楚你在问什么。也就是说,接口方法RevokeObjectParam返回一个int。请参阅:@TnTinMn:您提供的链接非常棒!它回答了我的问题,即什么是正确的方法签名。现在我肯定是从微软来的。