How to check whether the tlb file is registered in registry using C++?

一曲冷凌霜 提交于 2021-02-08 05:14:35

问题


I have created a class library using c#.And i have registered the class library using

regasm..

  RegAsm.exe Discovery.dll /tlb: Discovery.dll /codebase

Now i want to know whether the assembly is registered or not using c++. I need because I have to check the registry for this dll if it is not registered I have to registered it programatically if it is registered then i simply skip it.

so How can i know whether the assembly registered or not using c++...


回答1:


Why do you need to bother at all? There is no harm to registering it again if it IS already there.




回答2:


Use LoadRegTypeLib to load it, and check the return value for errors. For example:

HRESULT hr;
ITypeLib *libraryIntf;

hr = LoadRegTypeLib(IID_GuidOfTypeLibrary, LibraryVersionMajor,
    LibraryVersionMinor, 0, &libraryIntf);
if(SUCCEEDED(hr))
{
    libraryIntf->Release();
    libraryIntf = NULL;
    // Type library is registered and can be loaded.
}
else
{
    // Type library is not registered.
}



回答3:


Check the registry under HKEY_CLASSES_ROOT:

  • HKEY_CLASSES_ROOT\CLSID contains all class IDs
  • HKEY_CLASSES_ROOT\Interface contains all interface IDs
  • HKEY_CLASSES_ROOT\TypeLib contains all type library IDs

Use the RegOpenKeyEx function to open the key. If the key exists, the function returns success.




回答4:


Usually the library UUID can be found in the registry under HKEY_CLASSES_ROOT\CLSID{guid}. By checking for that key, you know if the dll was registered. The RegGetKeyValue may do the trick.



来源:https://stackoverflow.com/questions/1147053/how-to-check-whether-the-tlb-file-is-registered-in-registry-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!