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
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 使用 rss + c# 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01