개요 | |
윈도우의 레지스트리에 접근하기 위한 함수 및 코드들 . RegOpenKeyEx : 특정 registry key 열기. RegEnumKeyEx : 특정 registry key 하위 키들 열거하기. RegQueryValueEx : 열린키의 지정된 value name 의 type과 data 얻기. RegSetValueEx : 1개의 registry key 의 지정된 value name 에 type과 data 기록하기.
| |
|
함수 RegOpenKeyEx | |||||||||||||||||
LONG WINAPI RegOpenKeyEx( _In_ HKEY hKey, _In_opt_ LPCTSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult ); 특정 registry key 열기. registry key 란 regedit에서 보이는 경로의미함. 인자 kKey : regedit 에서 루트에 보이는 5개중 1개를 기록하면됨. 인자 lpSubkey : hKey 하위의 경로 기록. 대소문자 구분없음. RegOpenKeyEx functionOpens the specified registry key. Note that key names are not case sensitive. To perform transacted registry operations on a key, call the RegOpenKeyTransacted function. SyntaxC++ LONG WINAPI RegOpenKeyEx( _In_ HKEY hKey, _In_opt_ LPCTSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult ); Parameters
Return valueIf the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. RemarksUnlike the RegCreateKeyEx function, the RegOpenKeyEx function does not create the specified key if the key does not exist in the registry. Certain registry operations perform access checks against the security descriptor of the key, not the access mask specified when the handle to the key was obtained. For example, even if a key is opened with a samDesired of KEY_READ, it can be used to create registry keys if the key's security descriptor permits. In contrast, the RegSetValueEx function specifically requires that the key be opened with the KEY_SET_VALUE access right. If your service or application impersonates different users, do not use this function with HKEY_CURRENT_USER. Instead, call the RegOpenCurrentUser function. Note that operations that access certain registry keys are redirected. For more information, see Registry Virtualization and 32-bit and 64-bit Application Data in the Registry. ExamplesFor an example, see Deleting a Key with Subkeys. Requirements
See also | |||||||||||||||||
|
함수 RegEnumKeyEx | |||||||||||||
LONG WINAPI RegEnumKeyEx( _In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPTSTR lpName, _Inout_ LPDWORD lpcName, _Reserved_ LPDWORD lpReserved, _Inout_ LPTSTR lpClass, _Inout_opt_ LPDWORD lpcClass, _Out_opt_ PFILETIME lpftLastWriteTime ); 특정 register key 하위 키들 열거하기. RegEnumKeyEx functionEnumerates the subkeys of the specified open registry key. The function retrieves information about one subkey each time it is called. SyntaxC++ LONG WINAPI RegEnumKeyEx( _In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPTSTR lpName, _Inout_ LPDWORD lpcName, _Reserved_ LPDWORD lpReserved, _Inout_ LPTSTR lpClass, _Inout_opt_ LPDWORD lpcClass, _Out_opt_ PFILETIME lpftLastWriteTime ); Parameters
Return valueIf the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a system error code. If there are no more subkeys available, the function returns ERROR_NO_MORE_ITEMS. If the lpName buffer is too small to receive the name of the key, the function returns ERROR_MORE_DATA. RemarksTo enumerate subkeys, an application should initially call the RegEnumKeyEx function with the dwIndex parameter set to zero. The application should then increment the dwIndex parameter and call RegEnumKeyEx until there are no more subkeys (meaning the function returns ERROR_NO_MORE_ITEMS). The application can also set dwIndex to the index of the last subkey on the first call to the function and decrement the index until the subkey with the index 0 is enumerated. To retrieve the index of the last subkey, use the RegQueryInfoKey function. While an application is using the RegEnumKeyEx function, it should not make calls to any registration functions that might change the key being enumerated. Note that operations that access certain registry keys are redirected. For more information, see Registry Virtualization and 32-bit and 64-bit Application Data in the Registry. ExamplesFor an example, see Enumerating Registry Subkeys. Requirements
See also | |||||||||||||
|
함수 RegQueryValueEx | |||||||||||||
LONG WINAPI RegQueryValueEx( _In_ HKEY hKey, _In_opt_ LPCTSTR lpValueName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_opt_ LPBYTE lpData, _Inout_opt_ LPDWORD lpcbData ); RegQueryValueEx functionRetrieves the type and data for the specified value name associated with an open registry key. To ensure that any string values (REG_SZ, REG_MULTI_SZ, and REG_EXPAND_SZ) returned are null-terminated, use the RegGetValue function. SyntaxC++ LONG WINAPI RegQueryValueEx( _In_ HKEY hKey, _In_opt_ LPCTSTR lpValueName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_opt_ LPBYTE lpData, _Inout_opt_ LPDWORD lpcbData ); Parameters
Return valueIf the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a system error code. If the lpData buffer is too small to receive the data, the function returns ERROR_MORE_DATA. If the lpValueName registry value does not exist, the function returns ERROR_FILE_NOT_FOUND. RemarksAn application typically calls RegEnumValue to determine the value names and then RegQueryValueEx to retrieve the data for the names. If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, the string may not have been stored with the proper terminating null characters. Therefore, even if the function returns ERROR_SUCCESS, the application should ensure that the string is properly terminated before using it; otherwise, it may overwrite a buffer. (Note that REG_MULTI_SZ strings should have two terminating null characters.) One way an application can ensure that the string is properly terminated is to use RegGetValue, which adds terminating null characters if needed. If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, and the ANSI version of this function is used (either by explicitly calling RegQueryValueExA or by not defining UNICODE before including the Windows.h file), this function converts the stored Unicode string to an ANSI string before copying it to the buffer pointed to by lpData. When calling the RegQueryValueEx function with hKey set to the HKEY_PERFORMANCE_DATA handle and a value string of a specified object, the returned data structure sometimes has unrequested objects. Do not be surprised; this is normal behavior. When calling the RegQueryValueEx function, you should always expect to walk the returned data structure to look for the requested object. Note that operations that access certain registry keys are redirected. For more information, see Registry Virtualization and 32-bit and 64-bit Application Data in the Registry. ExamplesEnsure that you reinitialize the value pointed to by the lpcbData parameter each time you call this function. This is very important when you call this function in a loop, as in the following code example. C++ #include <windows.h> #include <malloc.h> #include <stdio.h> #define TOTALBYTES 8192 #define BYTEINCREMENT 4096 void main() { DWORD BufferSize = TOTALBYTES; DWORD cbData; DWORD dwRet; PPERF_DATA_BLOCK PerfData = (PPERF_DATA_BLOCK) malloc( BufferSize ); cbData = BufferSize; printf("\nRetrieving the data..."); dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA, TEXT("Global"), NULL, NULL, (LPBYTE) PerfData, &cbData ); while( dwRet == ERROR_MORE_DATA ) { // Get a buffer that is big enough. BufferSize += BYTEINCREMENT; PerfData = (PPERF_DATA_BLOCK) realloc( PerfData, BufferSize ); cbData = BufferSize; printf("."); dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA, TEXT("Global"), NULL, NULL, (LPBYTE) PerfData, &cbData ); } if( dwRet == ERROR_SUCCESS ) printf("\n\nFinal buffer size is %d\n", BufferSize); else printf("\nRegQueryValueEx failed (%d)\n", dwRet); } Requirements
See also | |||||||||||||
|
함수 RegSetValueEx | |||||||||||||
LONG WINAPI RegSetValueEx( _In_ HKEY hKey, _In_opt_ LPCTSTR lpValueName, _Reserved_ DWORD Reserved, _In_ DWORD dwType, _In_ const BYTE *lpData, _In_ DWORD cbData ); RegSetValueEx functionSets the data and type of a specified value under a registry key. SyntaxC++ LONG WINAPI RegSetValueEx(
_In_ HKEY hKey,
_In_opt_ LPCTSTR lpValueName,
_Reserved_ DWORD Reserved,
_In_ DWORD dwType,
_In_ const BYTE *lpData,
_In_ DWORD cbData
);
Parameters
Return valueIf the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. RemarksValue sizes are limited by available memory. However, storing large values in the registry can affect its performance. Long values (more than 2,048 bytes) should be stored as files, with the locations of the files stored in the registry. Application elements such as icons, bitmaps, and executable files should be stored as files and not be placed in the registry. If dwType is the REG_SZ, REG_MULTI_SZ, or REG_EXPAND_SZ type and the ANSI version of this function is used (either by explicitly calling RegSetValueExA or by not defining UNICODE before including the Windows.h file), the data pointed to by the lpData parameter must be an ANSI character string. The string is converted to Unicode before it is stored in the registry. Note that operations that access certain registry keys are redirected. For more information, see Registry Virtualization and 32-bit and 64-bit Application Data in the Registry. Requirements
See also | |||||||||||||
|
///763.
'VisualStudio.C++.C# > 코딩팁,함수활용,단편' 카테고리의 다른 글
C++ AMP. Math Libraries for C++ AMP (0) | 2016.09.14 |
---|---|
COM. Component Object Model. PC 레지스트리에 등록/제거. regsvr32 명령어. (0) | 2016.07.30 |
MFC. Slider 컨트롤 사용법. (0) | 2016.05.22 |
MFC. Radio button control 사용법. (0) | 2016.05.17 |
VC++. 대화상자 윈도우 좌표 지정하기. (0) | 2016.04.20 |
댓글