windows 获取 DLL 文件的 CLSID?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2280247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting CLSID for a DLL file?
提问by user202987
I want to create a small app to add and remove user defined context menu entries from the registry. To make this, somehow I need to get the CLSID of an arbitrary DLL so I can back up previous entries if they exist before writing new ones.
我想创建一个小应用程序来从注册表中添加和删除用户定义的上下文菜单条目。为了做到这一点,我需要以某种方式获取任意 DLL 的 CLSID,以便我可以在编写新条目之前备份以前的条目(如果它们存在)。
Although regsrv32
somehow manages to create this magical number, I didn't find any way to get that number myself.
尽管regsrv32
以某种方式设法创建了这个神奇的数字,但我自己没有找到任何方法来获得该数字。
I hope there is something better than this:
我希望有比这更好的东西:
- scanning registry for the DLL name
- if not found, register it, scan again, and then unregister it again
- 扫描注册表以获取 DLL 名称
- 如果没有找到,注册它,再次扫描,然后再次注销
If the DLL has been renamed, I can see a possibility for problems.
如果 DLL 已重命名,我可以看到出现问题的可能性。
回答by Trevor Tippins
You could consider calling LoadTypeLibExon the DLL specifying REGKIND_NONE and then examine get the TypeLibInfoinformation available via the ITypeLibinterface passed back to you.
你可以考虑调用LoadTypeLibEx的DLL指定REGKIND_NONE,然后检查得到TypeLibInfo通过提供信息的ITypeLib接口传回给您。
There's some information about this sort of thing on MSDN. It's an old VB6-focused link but has useful information about inspecting COM components in this way.
MSDN上有一些关于这类事情的信息。这是一个以 VB6 为重点的旧链接,但包含有关以这种方式检查 COM 组件的有用信息。
回答by sharptooth
You could try to use RegOverridePredefKey()to intercept what regsvr32 does to the registry - call RegOverridePredefKey(), then reproduce what regsvr32 does - LoadLibrary() the COM server, call DllRegisterServer() - then inspect the changes done. With RegOverridePredefKey() you will isolate the changes and not let them become persistent.
您可以尝试使用RegOverridePredefKey()来拦截 regsvr32 对注册表所做的事情 - 调用 RegOverridePredefKey(),然后重现 regsvr32 所做的事情 - LoadLibrary() COM 服务器,调用 DllRegisterServer() - 然后检查所做的更改。使用 RegOverridePredefKey() 您将隔离更改,而不是让它们变得持久。