com 대상

1368 단어
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;
}

좋은 웹페이지 즐겨찾기