⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registry.cpp

📁 这是书上的代码
💻 CPP
字号:

#include "stdafx.h"

#include "zddesk.h"
#include "registry.h"


// Create the specified key 
LONG CZDRegistry::Create(HKEY hRootKey, LPCTSTR lpszSubKey, REGSAM regSam, HKEY& hKey) 
{
   DWORD dwResult;

   LONG lRet = ::RegCreateKeyEx(
                      hRootKey,         // Root key
                      lpszSubKey,      // Subkey name
                      0L,               // Reserved
                      "",               // Class name
                      REG_OPTION_NON_VOLATILE,   // Permanent key
                      regSam,            // Security access
                      NULL,            // Security descriptor
                      &hKey,            // Key returned
                      &dwResult);      // Indicates if new key was created

   return(lRet);
}

// Open the specified key -- create it if it doesn't exist (call Create() method)
LONG CZDRegistry::Open(HKEY hRootKey, LPCTSTR lpszSubKey, REGSAM regSam, HKEY& hKey) 
{
   LONG lRet = ::RegOpenKeyEx(
                     hRootKey,         // Root to open
                     lpszSubKey,         // Key to open
                     0L,               // Reserved
                     regSam,            // Security access
                     &hKey);            // Key returned

   // This means that the key doesn't exist...so add it
   if(lRet == ERROR_FILE_NOT_FOUND)
      lRet = Create(hRootKey,lpszSubKey,regSam,hKey);

   return(lRet);
}

// Close the specifed key
LONG CZDRegistry::Close(HKEY hKey)
{
   LONG lRet = ::RegCloseKey(hKey);

   return(lRet);
}

// Get the specified key's value
LONG CZDRegistry::GetValue(HKEY hKey, LPCTSTR lpszValueName, DWORD dwDataType, 
                                    LPVOID lpvData, DWORD dwBuffSize)
{
   // These parameters must be passed by reference so copy the ones we 
   // passed by value to a temporary placeholder
   DWORD dwTempDataType = dwDataType;
   DWORD dwTempBuffSize = dwBuffSize;

   // Get the specified value
   LONG lRet = ::RegQueryValueEx(
                     hKey,               // Local machine config
                     lpszValueName,      // Value name
                     0L,               // Reserved
                     &dwTempDataType,   // Key type 
                     (LPBYTE) lpvData,   // Data buffer
                     &dwTempBuffSize);   // Length of data buffer
   
   return(lRet);
}

// Sets the value of the specified registry key
LONG CZDRegistry::SetValue(HKEY hKey, LPCTSTR lpszValueName, DWORD dwType,
                                 const LPVOID lpvData, DWORD dwDataSize)
{                           
   LONG lRet = ::RegSetValueEx(
                     hKey,               // Key handle
                     lpszValueName,      // Value name
                     0L,               // Reserved
                     dwType,            // Value type
                     (CONST BYTE *)lpvData,   // Data buffer
                     dwDataSize);      // Size of data

   return(lRet);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -