首页 > Windows开发 > 详细

c#获取com对象的progid

时间:2020-03-21 04:08:30      阅读:195      评论:0      收藏:0      [点我收藏+]
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);
          

        }
    }
}

  

c#获取com对象的progid

原文:https://www.cnblogs.com/coolyylu/p/12535395.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!