C#得到COM对象PROGID [英] C# Get progID from COM object

查看:1828
本文介绍了C#得到COM对象PROGID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方式来获得在C#中的COM对象的进程id。如 - 我有一个公开的文档对象,它是一个COM WebBrowser对象。有没有办法弄清楚,文档对象的ProgID是什么?

i would like to know if there is a way to get the progId of a com object in c#. eg - i have a webBrowser object that exposes a document object which is COM. is there a way to figure out what the progID of that document object is?

我知道你可以从PROGID对象,只是不知道该怎么做的其他方式左右。

I know you can get the object from progID, just not sure how to do the other way around.

推荐答案

您可以查询的IPersist 的GetClassID上。

You could query for IPersist, and GetClassID on it.

这让你的 CLSID 。然后调用 ProgIDFromCLSID

的PInvoke的声明是在这里。

这让你的ProgID

That gets you the ProgID.

编辑:

要查询的接口,你只是做一个投在C#中:

To query for an interface, you just do a cast in C#:

IPersist p = myObj as IPersist;
if (p != null)
{
    // phew, it worked...
}

在幕后,这是什么是实际发生的,如下所示的C ++:

Behind the scenes, this is what is actually happening, as shown here in C++:

IUnknown *pUnk = // ... get object from somewhere

IPersist *pPersist = 0;
if (SUCCEEDED(pUnk->QueryInterface(IID_IPersist, (void **)&pPersist)))
{
    // phew, it worked...
}

(但没有人用手写的东西,这些天,作为智能指针困扰几乎可以模拟C#经验。)

(But no one bothers with writing that stuff by hand these days, as a smart pointer can pretty much simulate the C# experience.)

这篇关于C#得到COM对象PROGID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆