C# Get progID from COM object(C# 从 COM 对象获取 progID)
问题描述
我想知道是否有办法在 c# 中获取 com 对象的 progId.例如 - 我有一个 webBrowser 对象,它公开了一个 COM 文档对象.有没有办法找出该文档对象的 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:
That gets you the CLSID. Then call 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# 从 COM 对象获取 progID
基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
