mfx_win_reg_key.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* ****************************************************************************** *\
  2. Copyright (C) 2012-2014 Intel Corporation. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. - Redistributions of source code must retain the above copyright notice,
  6. this list of conditions and the following disclaimer.
  7. - Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. - Neither the name of Intel Corporation nor the names of its contributors
  11. may be used to endorse or promote products derived from this software
  12. without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
  14. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. File Name: mfx_win_reg_key.h
  24. \* ****************************************************************************** */
  25. #if !defined(__MFX_WIN_REG_KEY_H)
  26. #define __MFX_WIN_REG_KEY_H
  27. #if defined(_WIN32) || defined(_WIN64)
  28. #include <windows.h>
  29. #include "mfxplugin.h"
  30. #include "mfx_dispatcher_log.h"
  31. namespace MFX {
  32. template<class T> struct RegKey{};
  33. template<> struct RegKey<bool>{enum {type = REG_DWORD};};
  34. template<> struct RegKey<mfxU32>{enum {type = REG_DWORD};};
  35. template<> struct RegKey<mfxPluginUID>{enum {type = REG_BINARY};};
  36. template<> struct RegKey<mfxVersion>{enum {type = REG_DWORD};};
  37. template<> struct RegKey<char*>{enum {type = REG_SZ};};
  38. template<> struct RegKey<wchar_t*>{enum {type = REG_SZ};};
  39. class WinRegKey
  40. {
  41. public:
  42. // Default constructor
  43. WinRegKey(void);
  44. // Destructor
  45. ~WinRegKey(void);
  46. // Open a registry key
  47. bool Open(HKEY hRootKey, const wchar_t *pSubKey, REGSAM samDesired);
  48. bool Open(WinRegKey &rootKey, const wchar_t *pSubKey, REGSAM samDesired);
  49. // Query value
  50. bool QueryInfo(LPDWORD lpcSubkeys);
  51. bool QueryValueSize(const wchar_t *pValueName, DWORD type, LPDWORD pcbData);
  52. bool Query(const wchar_t *pValueName, DWORD type, LPBYTE pData, LPDWORD pcbData);
  53. bool Query(const wchar_t *pValueName, wchar_t *pData, mfxU32 &nData) {
  54. DWORD dw = (DWORD)nData;
  55. if (!Query(pValueName, RegKey<wchar_t*>::type, (LPBYTE)pData, &dw)){
  56. return false;
  57. }
  58. nData = dw;
  59. return true;
  60. }
  61. // Enumerate value names
  62. bool EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType);
  63. bool EnumKey(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName);
  64. protected:
  65. // Release the object
  66. void Release(void);
  67. HKEY m_hKey; // (HKEY) handle to the opened key
  68. private:
  69. // unimplemented by intent to make this class non-copyable
  70. WinRegKey(const WinRegKey &);
  71. void operator=(const WinRegKey &);
  72. };
  73. template<class T>
  74. inline bool QueryKey(WinRegKey & key, const wchar_t *pValueName, T &data ) {
  75. DWORD size = sizeof(data);
  76. return key.Query(pValueName, RegKey<T>::type, (LPBYTE) &data, &size);
  77. }
  78. template<>
  79. inline bool QueryKey<bool>(WinRegKey & key, const wchar_t *pValueName, bool &data ) {
  80. mfxU32 value = 0;
  81. bool bRes = QueryKey(key, pValueName, value);
  82. data = (1 == value);
  83. return bRes;
  84. }
  85. } // namespace MFX
  86. #endif // #if defined(_WIN32) || defined(_WIN64)
  87. #endif // __MFX_WIN_REG_KEY_H