none
求C#与COM互操作的书或资料 RRS feed

  • 问题

  • 这几天在看COM和C#互操作的应用,看了几个例子和MSDN上的文章,比如,http://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx#vcwlkcominteroppart1cclienttutorialanchor1

    但还是不是很明白其中的细节,比如去哪里找“original MIDL version of the interface:”,函数参数类型互相转换的依据怎么弄,等等,比如网上找了两个关于 IOleCommandTarget网上找到两个实现,目前看着很歇菜,不确定哪一个是正确的,或者那个更好,依据在哪里?

    [ComImport, ComVisible(true),Guid("B722BCCB-4E68-101B-A2BC-00AA00404770"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
        public interface IOleCommandTarget
        {
            [return: MarshalAs(UnmanagedType.I4)]
            [PreserveSig]
            int QueryStatus(
                [In] IntPtr pguidCmdGroup,
                [In, MarshalAs(UnmanagedType.U4)] uint cCmds,
                [In, Out, MarshalAs(UnmanagedType.Struct)] ref tagOLECMD prgCmds,
                [In, Out] IntPtr pCmdText);
    
            [return: MarshalAs(UnmanagedType.I4)]
            [PreserveSig]
            int Exec(           
                [In] IntPtr pguidCmdGroup,
                [In, MarshalAs(UnmanagedType.U4)] uint nCmdID,
                [In, MarshalAs(UnmanagedType.U4)] uint nCmdexecopt,
                [In] IntPtr pvaIn,
                [In, Out] IntPtr pvaOut);
        }
       
        [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("B722BCCB-4E68-101B-A2BC-00AA00404770"), ComVisible(true)]
        public interface IOleCommandTarget
        {
            [return: MarshalAs(UnmanagedType.I4)]
            [PreserveSig]
            int QueryStatus(ref Guid pguidCmdGroup, int cCmds, [In, Out] OLECMD prgCmds, [In, Out] IntPtr pCmdText);
            [return: MarshalAs(UnmanagedType.I4)]
            [PreserveSig]
            int Exec(ref Guid pguidCmdGroup, int nCmdID, int nCmdexecopt, [In, MarshalAs(UnmanagedType.LPArray)] object[] pvaIn, ref int pvaOut);
        }

    高手推荐些详细的资料,扫扫盲,谢谢


    • 已编辑 cylixhui 2013年3月19日 15:52
    2013年3月19日 15:48

答案

全部回复