com 对象

来源:互联网 发布:免费备案域名 编辑:程序博客网 时间:2024/04/29 23:05

1、如何判断一个COM对象是否可用

bool IsCOMAvailable(CString strGUID){    // 1. Try to open the HKEY_CLASSES_ROOT\CLSID\{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} key    CString strKeyName = _T("CLSID\\") + strGUID;    HKEY hClsidKey;    if( ::RegOpenKeyEx( HKEY_CLASSES_ROOT, strKeyName, 0, KEY_QUERY_VALUE, &hClsidKey ) == ERROR_SUCCESS )    {        // 2. Continue to open CLSID\{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\InProcServer32\(Default)        HKEY hInProcServer32Key;        if( ::RegOpenKeyEx( hClsidKey, _T( "InProcServer32" ), 0, KEY_QUERY_VALUE, &hInProcServer32Key ) == ERROR_SUCCESS )        {            TCHAR tszServerPathName[_MAX_PATH];            DWORD dwSize = sizeof( tszServerPathName );            DWORD dwType;            // 3. Get the com dll path            if( ::RegQueryValueEx( hInProcServer32Key, NULL, NULL, &dwType, (LPBYTE)tszServerPathName, &dwSize ) == ERROR_SUCCESS )            {                if( dwType != REG_SZ )                    return false;                // 4. If the dll file exist                CFileFind fileFind;                if(fileFind.FindFile(tszServerPathName))                    return true;            }            ::CloseHandle(hInProcServer32Key);        }        ::CloseHandle(hClsidKey);    }    return false;}


原创粉丝点击