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组件跟设置有关系,如下图