C# 获取COM对象 ProgId ClsId

https://social.msdn.microsoft.com/Forums/vstudio/en-US/fe262fdd-a93f-427e-8771-2c64e7ac3064/getting-the-progid-from-type?forum=csharpgeneral
  • Something like this might work: [DllImport("ole32.dll")] static extern int ProgIDFromCLSID([In] ref Guid clsid, [MarshalAs(UnmanagedType.LPWStr)] out string lplpszProgID); . . . object tmpComObj = Activator.CreateInstance(comType); IPersist persist = comObj as IPersist; if (persist != null) { Guid classId; persist.GetClassID(out classId); string progId; ProgIDFromCLSID(ref classId, out progId); Console.WriteLine("Progid = {0}, CLSID = {1}", progId, classId); } Marshal.ReleaseComObject(tmpComObj);
 
posted @ 2014-11-07 10:17  adodo1  Views(1849)  Comments(0Edit  收藏  举报