#include "registryhelper.h"
#include <assert.h>
Go to the source code of this file.
Functions | |
int | CreateKey (LPCTSTR lpSubKey, LPTSTR lpClass, LPTSTR lpData) |
LPTSTR | QueryKey (HKEY hKey, LPTSTR sPsth, LPCTSTR lpSubKey, LPTSTR databuffer, int dataBufferSize) |
|
Definition at line 20 of file registryhelper.c. Referenced by createConfigCountKey(), and saveConfiguration().
00021 { 00022 HKEY keyHandle; 00023 DWORD lpdw; 00024 00025 //In order to set the value you must specify the length of the lpData. 00026 int aLen = strlen(lpData) + 1; 00027 00028 //This will create the key if it does not exist or update it if it does. 00029 long rtn = RegCreateKeyEx(HKEY_CURRENT_USER, 00030 lpSubKey, 0, "Anything", 00031 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &keyHandle, &lpdw); 00032 00033 if(rtn == ERROR_SUCCESS) 00034 { 00035 //This will write the data to the newly created key or update it. 00036 rtn = RegSetValueEx(keyHandle, lpClass, 0, REG_SZ, (LPBYTE)lpData, aLen); 00037 //Good programming practice, close what you open. 00038 rtn = RegCloseKey(keyHandle); 00039 } 00040 00041 return rtn; 00042 } |
|
Definition at line 51 of file registryhelper.c. Referenced by loadConfiguration().
00052 { 00053 DWORD lpcbData = dataBufferSize; 00054 DWORD lpType; 00055 00056 assert(sPsth != NULL); 00057 assert(lpSubKey != NULL); 00058 assert(databuffer != NULL); 00059 00060 ZeroMemory(databuffer, dataBufferSize); 00061 00062 if(RegOpenKeyEx(hKey, sPsth, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) 00063 { 00064 TCHAR* buffer = (TCHAR*) malloc(dataBufferSize); 00065 int resultCode = RegQueryValueEx(hKey, lpSubKey, NULL, &lpType, (BYTE*)buffer, &lpcbData); 00066 if (resultCode == ERROR_MORE_DATA) 00067 { 00068 free(buffer); 00069 buffer = (TCHAR*) malloc(lpcbData); 00070 RegQueryValueEx(hKey, lpSubKey, NULL, &lpType, (BYTE*)buffer, &lpcbData); 00071 } 00072 00073 // Something read from Registry 00074 if (lpcbData != (DWORD) dataBufferSize) 00075 { 00076 assert(lpcbData <= (DWORD) dataBufferSize); 00077 lstrcpyn(databuffer, buffer, lpcbData); 00078 } 00079 00080 free(buffer); 00081 } 00082 00083 RegCloseKey(hKey); 00084 00085 return databuffer; 00086 } |