Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.0 KiB

  1. // Copyright (c) 2000 - 2000 Microsoft Corporation. All Rights Reserved.
  2. //
  3. // reghlp.cpp - registration/enumeration part of DMO runtime
  4. //
  5. #include <windows.h>
  6. #include <tchar.h>
  7. #include <guiddef.h>
  8. #include <ks.h>
  9. #include <strsafe.h>
  10. #define DMO_REGISTRY_HIVE HKEY_CLASSES_ROOT
  11. #define DMO_REGISTRY_PATH TEXT("DirectShow\\MediaObjects")
  12. #define CPU_RESOURCES_STR "SystemResources"
  13. // Automatically calls RegCloseKey when leaving scope
  14. class CAutoCreateHKey {
  15. public:
  16. CAutoCreateHKey(HKEY hKey, TCHAR* szSubKey, HKEY *phKey) {
  17. if (RegCreateKeyEx(hKey,
  18. szSubKey,
  19. 0,
  20. TEXT(""),
  21. REG_OPTION_NON_VOLATILE,
  22. MAXIMUM_ALLOWED,
  23. NULL,
  24. phKey,
  25. NULL) != ERROR_SUCCESS)
  26. m_hKey = *phKey = NULL;
  27. else
  28. m_hKey = *phKey;
  29. }
  30. ~CAutoCreateHKey() {
  31. if (m_hKey)
  32. RegCloseKey(m_hKey);
  33. }
  34. HKEY m_hKey;
  35. };
  36. class CAutoOpenHKey {
  37. public:
  38. CAutoOpenHKey(HKEY hKey, TCHAR* szSubKey, HKEY *phKey, REGSAM samDesired = MAXIMUM_ALLOWED) {
  39. if (RegOpenKeyEx(hKey,
  40. szSubKey,
  41. 0,
  42. samDesired,
  43. phKey) != ERROR_SUCCESS)
  44. m_hKey = *phKey = NULL;
  45. else
  46. m_hKey = *phKey;
  47. }
  48. ~CAutoOpenHKey() {
  49. if (m_hKey)
  50. RegCloseKey(m_hKey);
  51. }
  52. HKEY m_hKey;
  53. };
  54. /////////////////////////////////////////////////////////////////////////////
  55. //
  56. // DMO Registration code
  57. //
  58. //
  59. // Public entry point
  60. //
  61. STDAPI DMORegisterCpuResources
  62. (
  63. REFCLSID clsidDMO,
  64. unsigned long ulCpuResources
  65. )
  66. {
  67. TCHAR szSubkeyName[80];
  68. if (clsidDMO == GUID_NULL)
  69. return E_INVALIDARG;
  70. // open the main DMO key
  71. HKEY hMainKey;
  72. CAutoOpenHKey kMain(DMO_REGISTRY_HIVE, DMO_REGISTRY_PATH, &hMainKey);
  73. if (hMainKey == NULL)
  74. return E_FAIL;
  75. // open the object specific key underneath the main key
  76. //DMOGuidToStr(szSubkeyName, clsidDMO); // BUGBUG: redundant
  77. StringCchPrintf(szSubkeyName,sizeof(szSubkeyName)/sizeof(TCHAR),TEXT("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"),
  78. clsidDMO.Data1, clsidDMO.Data2, clsidDMO.Data3, clsidDMO.Data4[0], clsidDMO.Data4[1],
  79. clsidDMO.Data4[2], clsidDMO.Data4[3], clsidDMO.Data4[4], clsidDMO.Data4[5],
  80. clsidDMO.Data4[6], clsidDMO.Data4[7]);
  81. HKEY hObjectKey;
  82. CAutoOpenHKey kObject(hMainKey, szSubkeyName, &hObjectKey);
  83. if (hObjectKey == NULL)
  84. return E_FAIL;
  85. // set the default value of the CPU Resources key to the value
  86. if (RegSetValueEx(hObjectKey, TEXT(CPU_RESOURCES_STR), (DWORD)0, REG_DWORD, (CONST BYTE *)&ulCpuResources, sizeof(DWORD))
  87. != ERROR_SUCCESS)
  88. return E_FAIL;
  89. return NOERROR;
  90. }
  91. //
  92. // End registry helper code
  93. //
  94. /////////////////////////////////////////////////////////////////////////////