c#获取com对象的progid


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
namespace ImportExcelBill
{
    [InterfaceType(1)]
    [Guid("0000010C-0000-0000-C000-000000000046")]
    public interface IPersist
    {
        void GetClassID(out Guid pClassID);
    }

    public class ICMOList
    {
        [DllImport("ole32.dll")]
        static extern int ProgIDFromCLSID([In] ref Guid clsid, [MarshalAs(UnmanagedType.LPWStr)] out string lplpszProgID);
        public void MainFunction(String sKey  , Object oList , Boolean bCancel  )
        {
            string progId = "";
            IPersist persist = oList as IPersist;
            if (persist != null)
            {
                Guid classId;
                persist.GetClassID(out classId);
               
                ProgIDFromCLSID(ref classId, out progId);
            }
            Marshal.ReleaseComObject(oList);


            MessageBox.Show(progId);
          

        }
    }
}

  

有些com组件跟设置有关系,如下图


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM