Exemplo n.º 1
0
//
//   FUNCTION: RegisterInprocServer
//
//   PURPOSE: Register the in-process component in the registry.
//
//   PARAMETERS:
//   * pszModule - Path of the module that contains the component
//   * clsid - Class ID of the component
//   * pszFriendlyName - Friendly name
//   * pszThreadModel - Threading model
//
//   NOTE: The function creates the HKCR\CLSID\{<CLSID>} key in the registry.
//
//   HKCR
//   {
//      NoRemove CLSID
//      {
//          ForceRemove {<CLSID>} = s '<Friendly Name>'
//          {
//              InprocServer32 = s '%MODULE%'
//              {
//                  val ThreadingModel = s '<Thread Model>'
//              }
//          }
//      }
//   }
//
HRESULT RegisterInprocServer(PCWSTR pszModule, const CLSID& clsid, PCWSTR pszFriendlyName, PCWSTR pszThreadModel)
{
    if (pszModule == NULL || pszThreadModel == NULL)
    {
        return E_INVALIDARG;
    }

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    // Create the HKCR\CLSID\{<CLSID>} key.
    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey),
                     #ifdef CATCHCOPY_ROOT_MODE
                         L"CLSID\\%s"
                     #else
                         L"Software\\Classes\\CLSID\\%s"
                     #endif
                         , szCLSID);
    if (SUCCEEDED(hr))
    {
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName);

        // Create the HKCR\CLSID\{<CLSID>}\InprocServer32 key.
        if (SUCCEEDED(hr))
        {
            hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey),
                     #ifdef CATCHCOPY_ROOT_MODE
                         L"CLSID\\%s\\InprocServer32"
                     #else
                         L"Software\\Classes\\CLSID\\%s\\InprocServer32"
                     #endif
                                 , szCLSID);
            if (SUCCEEDED(hr))
            {
                // Set the default value of the InprocServer32 key to the
                // path of the COM module.
                hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszModule);
                if (SUCCEEDED(hr))
                {
                    // Set the threading model of the component.
                    hr = SetHKCRRegistryKeyAndValue(szSubkey, L"ThreadingModel", pszThreadModel);
                }
            }
        }
    }

    return hr;
}
Exemplo n.º 2
0
HRESULT
RegisterInprocServer(
    PCWSTR pszModule,
    const CLSID& clsid,
    PCWSTR pszFriendlyName,
    PCWSTR pszThreadModel
  )
{
    if (pszModule == NULL || pszThreadModel == NULL)
        return E_INVALIDARG;

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    do {
        // Create the HKCR\CLSID\{<CLSID>} key.
        hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID);
        if (!SUCCEEDED(hr))
            break;
  
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName);
        if (!SUCCEEDED(hr))
            break;

        // Create the HKCR\CLSID\{<CLSID>}\InprocServer32 key.
        hr = StringCchPrintf(
            szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s\\InprocServer32", szCLSID
        );
        if (!SUCCEEDED(hr))
            break;

        // Set the default value of the InprocServer32 key to the 
        // path of the COM module.
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszModule);
        if (!SUCCEEDED(hr))
            break;

        hr = SetHKCRRegistryKeyAndValue(
            szSubkey, L"ThreadingModel", pszThreadModel
        );

    } while (0);

    return hr;
}
Exemplo n.º 3
0
//
//   函数名称: RegisterInprocServer
//
//   作用: 在注册表中注册进程内组件
//
//   参数:
//   * pszModule -包含该组件模块的路径
//   * clsid -组件的类ID
//   * pszFriendlyName -友元名称
//   * pszThreadModel -线程模型
//
//  
//  注意: 该方法在注册表中创建了HKCR\CLSID\{<CLSID>}注册项.
//
//   HKCR
//   {
//      NoRemove CLSID
//      {
//          ForceRemove {<CLSID>} = s '<Friendly Name>'
//          {
//              InprocServer32 = s '%MODULE%'
//              {
//                  val ThreadingModel = s '<Thread Model>'
//              }
//          }
//      }
//   }
//
HRESULT RegisterInprocServer(PCWSTR pszModule, const CLSID& clsid, 
    PCWSTR pszFriendlyName, PCWSTR pszThreadModel)
{
    if (pszModule == NULL || pszThreadModel == NULL)
    {
        return E_INVALIDARG;
    }

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    // 创建 HKCR\CLSID\{<CLSID>}注册项.
    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID);
    if (SUCCEEDED(hr))
    {
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName);

        //创建 HKCR\CLSID\{<CLSID>}\InprocServer32注册项.
        if (SUCCEEDED(hr))
        {
            hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), 
                L"CLSID\\%s\\InprocServer32", szCLSID);
            if (SUCCEEDED(hr))
            {
                //以InprocServer32注册项的值作为为COM模块的路径的默认值  
                
                hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszModule);
                if (SUCCEEDED(hr))
                {
                    //为组件设置线程模型.
                    hr = SetHKCRRegistryKeyAndValue(szSubkey, 
                        L"ThreadingModel", pszThreadModel);
                }
            }
        }
    }

    return hr;
}
Exemplo n.º 4
0
HRESULT
RegisterShellExtContextMenuHandler(
    PCWSTR pszFileType,
    const CLSID& clsid,
    PCWSTR pszFriendlyName
    )
{
    if (pszFileType == NULL)
        return E_INVALIDARG;

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    // If pszFileType starts with '.', try to read the default value of the 
    // HKCR\<File Type> key which contains the ProgID to which the file type 
    // is linked.
    if (*pszFileType == L'.') {
        wchar_t szDefaultVal[260];
        hr = GetHKCRRegistryKeyAndValue(
            pszFileType, NULL, szDefaultVal, sizeof(szDefaultVal)
        );

        // If the key exists and its default value is not empty, use the 
        // ProgID as the file type.
        if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0') {
            pszFileType = szDefaultVal;
        }
    }

    // Create the key HKCR\<File Type>\shellex\ContextMenuHandlers\{<CLSID>}
    hr = StringCchPrintf(
        szSubkey,
        ARRAYSIZE(szSubkey), 
        L"%s\\shellex\\ContextMenuHandlers\\%s",
        pszFileType,
        szCLSID
    );

    if (SUCCEEDED(hr)) {
        // Set the default value of the key.
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName);
    }

    return hr;
}
Exemplo n.º 5
0
HRESULT RegisterShellExtContextMenuHandler(
    PCWSTR pszFileType, const CLSID& clsid, PCWSTR pszFriendlyName)
{
    if (pszFileType == NULL)
    {
        return E_INVALIDARG;
    }

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    //如果文件的类型是以'.'开头的,然后在注册表的HKCR\<File Type>下获取该文件类型的对应的Program ID来关联该文件
    if (*pszFileType == L'.')
    {
        wchar_t szDefaultVal[260];
        hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal, 
            sizeof(szDefaultVal));

        // 如果该键存在且不为空, 使用ProgID 为该文件类型
        if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0')
        {
            pszFileType = szDefaultVal;
        }
    }

    // 创建键  HKCR\<File Type>\shellex\ContextMenuHandlers\{<CLSID>}
    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), 
        L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, szCLSID);
    if (SUCCEEDED(hr))
    {
        // 为该键设置默认值.
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName);
    }

    return hr;
}
Exemplo n.º 6
0
//
//   函数名称: RegisterShellExtInfotipHandler
//
//   作用: 注册shell 信息提示处理方法.
//
//   参数:
//   * pszFileType - 要处理文件的类型,如“*”代表所有的文件类型, 
//                   “.txt”代表.txt文件类型。参数不能为空
//   * clsid - 组件的类ID。
//
//   注意: 该方法在注册表中创建了以下注册信息。
//
//   HKCR
//   {
//      NoRemove <File Type>
//      {
//          NoRemove shellex
//          {
//              {00021500-0000-0000-C000-000000000046} = s '{<CLSID>}'
//          }
//      }
//   }
//
HRESULT RegisterShellExtInfotipHandler(PCWSTR pszFileType, const CLSID& clsid)
{
    if (pszFileType == NULL)
    {
        return E_INVALIDARG;
    }

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    // 如果 pszFileType以‘.’开始,就试着去找包含ProgID的HKCR\<FIle Type>的默认值
    if (*pszFileType == L'.')
    {
        wchar_t szDefaultVal[260];
        hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal, 
            sizeof(szDefaultVal));

        // 如果key存在并且默认值不空,就用ProgID作为文件的类型
        if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0')
        {
            pszFileType = szDefaultVal;
        }
    }

    //创建注册项 
    // HKCR\<File Type>\shellex\{00021500-0000-0000-C000-000000000046}
    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), 
        L"%s\\shellex\\{00021500-0000-0000-C000-000000000046}", pszFileType);
    if (SUCCEEDED(hr))
    {
        //设置注册项的默认值.
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, szCLSID);
    }

    return hr;
}