00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00050 #ifndef WINSTL_INCL_WINSTL_REGISTRY_HPP_REG_TRAITS
00051 #define WINSTL_INCL_WINSTL_REGISTRY_HPP_REG_TRAITS
00052
00053 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00054 # define WINSTL_VER_WINSTL_REGISTRY_HPP_REG_TRAITS_MAJOR 3
00055 # define WINSTL_VER_WINSTL_REGISTRY_HPP_REG_TRAITS_MINOR 5
00056 # define WINSTL_VER_WINSTL_REGISTRY_HPP_REG_TRAITS_REVISION 1
00057 # define WINSTL_VER_WINSTL_REGISTRY_HPP_REG_TRAITS_EDIT 77
00058 #endif
00059
00060
00061
00062
00063
00064 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00065 # include <winstl/winstl.h>
00066 #endif
00067 #ifndef WINSTL_INCL_WINSTL_REGISTRY_UTIL_HPP_DEFS
00068 # include <winstl/registry/util/defs.hpp>
00069 #endif
00070 #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS
00071 # include <winstl/system/system_traits.hpp>
00072 #endif
00073
00074
00075
00076
00077
00078 #ifndef _WINSTL_NO_NAMESPACE
00079 # if defined(_STLSOFT_NO_NAMESPACE) || \
00080 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00081
00082 namespace winstl
00083 {
00084 # else
00085
00086
00087 namespace stlsoft
00088 {
00089
00090 namespace winstl_project
00091 {
00092
00093 # endif
00094 #endif
00095
00096
00097
00098 #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
00099
00108 template <ss_typename_param_k C>
00109 struct reg_traits
00110 : public system_traits<C>
00111 {
00114 public:
00116 typedef C char_type;
00118 typedef ws_size_t size_type;
00120 typedef ws_ptrdiff_t difference_type;
00122 typedef HKEY hkey_type;
00124 typedef reg_string_t string_type;
00126 typedef FILETIME time_type;
00128 typedef LONG result_type;
00130
00133 public:
00137 static hkey_type key_dup( hkey_type hkey
00138 , REGSAM samDesired = KEY_ALL_ACCESS
00139 , result_type* result = NULL);
00141 static hkey_type reg_dup_key( hkey_type hkey
00142 , REGSAM samDesired = KEY_ALL_ACCESS
00143 , result_type* result = NULL);
00145 static result_type reg_open_key( hkey_type hkey,
00146 char_type const* sub_key_name,
00147 hkey_type* hkey_result,
00148 REGSAM samDesired = KEY_ALL_ACCESS);
00150 static result_type reg_create_key( hkey_type hkey,
00151 char_type const* sub_key_name,
00152 hkey_type* hkey_result,
00153 REGSAM samDesired = KEY_ALL_ACCESS);
00154 static result_type reg_create_key( hkey_type hkey,
00155 char_type const* sub_key_name,
00156 hkey_type* hkey_result,
00157 ws_bool_t& bCreated,
00158 REGSAM samDesired = KEY_ALL_ACCESS);
00160 static result_type reg_delete_key( hkey_type hkey,
00161 char_type const* sub_key_name);
00163 static result_type reg_query_value(hkey_type hkey,
00164 char_type const* valueName,
00165 ws_dword_t& valueType,
00166 void* data,
00167 size_type &cbData);
00169 static result_type reg_set_value( hkey_type hkey
00170 , char_type const* valueName
00171 , ws_dword_t valueType
00172 , void const* data
00173 , size_type cbData);
00175 static result_type reg_delete_value(hkey_type hkey
00176 , char_type const* valueName);
00177
00179 static result_type reg_delete_tree(
00180 hkey_type hkey
00181 , char_type const* sub_key_name
00182 );
00183
00185 static result_type reg_query_info( hkey_type hkey,
00186 char_type* key_class,
00187 size_type* cch_key_class,
00188 ws_uint32_t* c_sub_keys,
00189 size_type* cch_sub_key_max,
00190 size_type* cch_key_class_max,
00191 ws_uint32_t* c_values,
00192 size_type* cch_valueName_max,
00193 size_type* cb_value_data_max,
00194 size_type* cb_security_descriptor_max,
00195 time_type* time_last_write);
00197 static result_type reg_enum_key( hkey_type hkey,
00198 ws_dword_t index,
00199 char_type* key_name,
00200 size_type* cch_key_name,
00201 time_type* time_last_write = NULL);
00205 static result_type reg_enum_key( hkey_type hkey,
00206 ws_dword_t index,
00207 char_type* key_name,
00208 size_type* cch_key_name,
00209 char_type* key_class,
00210 size_type* cch_key_class,
00211 time_type* time_last_write);
00213 static result_type reg_enum_value( hkey_type hkey,
00214 ws_dword_t index,
00215 char_type* valueName,
00216 size_type* cch_valueName,
00217 ws_dword_t* valueType,
00218 void* data,
00219 size_type &cbData);
00221 static result_type reg_enum_value( hkey_type hkey,
00222 ws_dword_t index,
00223 char_type* valueName,
00224 size_type* cch_valueName);
00226 };
00227
00228 #else
00229
00230 template <ss_typename_param_k C>
00231 struct reg_traits;
00232
00233 STLSOFT_TEMPLATE_SPECIALISATION
00234 struct reg_traits<ws_char_a_t>
00235 : public system_traits<ws_char_a_t>
00236 {
00237 public:
00238 typedef ws_char_a_t char_type;
00239 typedef ws_size_t size_type;
00240 typedef ws_ptrdiff_t difference_type;
00241 typedef HKEY hkey_type;
00242 typedef reg_string_a_t string_type;
00243 typedef FILETIME time_type;
00244 typedef LONG result_type;
00245
00246 public:
00247 static hkey_type key_dup(hkey_type hkey, REGSAM samDesired, result_type *result = NULL)
00248 {
00249 return reg_dup_key(hkey, samDesired, result);
00250 }
00251 static hkey_type reg_dup_key(hkey_type hkey, REGSAM samDesired, result_type *result = NULL)
00252 {
00253 hkey_type hkeyDup;
00254 result_type res = ::RegOpenKeyExA(hkey, "", 0, samDesired, &hkeyDup);
00255
00256 if(ERROR_SUCCESS != res)
00257 {
00258 hkeyDup = NULL;
00259 }
00260
00261 if(NULL != result)
00262 {
00263 *result = res;
00264 }
00265
00266 return hkeyDup;
00267 }
00268
00269 static result_type reg_open_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, REGSAM samDesired = KEY_ALL_ACCESS)
00270 {
00271 return ::RegOpenKeyExA(hkey, sub_key_name, 0, samDesired, hkey_result);
00272 }
00273
00274 static result_type reg_create_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, REGSAM samDesired = KEY_ALL_ACCESS)
00275 {
00276 return ::RegCreateKeyExA(hkey, sub_key_name, 0, NULL, 0, samDesired, NULL, hkey_result, NULL);
00277 }
00278
00279 static result_type reg_create_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, ws_bool_t &bCreated, REGSAM samDesired = KEY_ALL_ACCESS)
00280 {
00281 DWORD disposition;
00282 result_type res = ::RegCreateKeyExA(hkey, sub_key_name, 0, NULL, 0, samDesired, NULL, hkey_result, &disposition);
00283
00284 bCreated = (ERROR_SUCCESS == res) && (REG_CREATED_NEW_KEY == disposition);
00285
00286 return res;
00287 }
00288
00289 static result_type reg_delete_key(hkey_type hkey, char_type const* sub_key_name)
00290 {
00291 return ::RegDeleteKeyA(hkey, sub_key_name);
00292 }
00293
00294 static result_type reg_query_value(hkey_type hkey, char_type const* valueName, ws_dword_t& valueType, void* data, size_type &cbData)
00295 {
00296 return ::RegQueryValueExA(hkey, valueName, NULL, &valueType, static_cast<LPBYTE>(data), reinterpret_cast<LPDWORD>(&cbData));
00297 }
00298
00299 static result_type reg_set_value(hkey_type hkey, char_type const* valueName, ws_dword_t valueType, void const* data, size_type cbData)
00300 {
00301 return ::RegSetValueExA(hkey, valueName, 0, valueType, static_cast<BYTE const*>(data), static_cast<DWORD>(cbData));
00302 }
00303
00304 static result_type reg_delete_value(hkey_type hkey, char_type const* valueName)
00305 {
00306 return ::RegDeleteValueA(hkey, valueName);
00307 }
00308
00309 static result_type reg_delete_tree(
00310 hkey_type hkey
00311 , char_type const* sub_key_name
00312 )
00313 {
00314 result_type res = execute_dynamic_("advapi32.dll", "RegDeleteTreeA", hkey, sub_key_name);
00315
00316 if(ERROR_PROC_NOT_FOUND == res)
00317 {
00318 res = execute_dynamic_("shlwapi.dll", "SHDeleteKeyA", hkey, sub_key_name);
00319 }
00320
00321 return res;
00322 }
00323
00324 static result_type reg_query_info( hkey_type hkey,
00325 char_type* key_class,
00326 size_type* cch_key_class,
00327 ws_uint32_t* c_sub_keys,
00328 size_type* cch_sub_key_max,
00329 size_type* cch_key_class_max,
00330 ws_uint32_t* c_values,
00331 size_type* cch_valueName_max,
00332 size_type* cb_value_data_max,
00333 size_type* cb_security_descriptor_max,
00334 time_type* time_last_write)
00335 {
00336 if( NULL == cch_key_class &&
00337 NULL != key_class)
00338 {
00339 return ERROR_INVALID_PARAMETER;
00340 }
00341
00342 return ::RegQueryInfoKeyA(hkey, key_class, reinterpret_cast<LPDWORD>(cch_key_class), NULL, reinterpret_cast<LPDWORD>(c_sub_keys), reinterpret_cast<LPDWORD>(cch_sub_key_max), reinterpret_cast<LPDWORD>(cch_key_class_max), reinterpret_cast<LPDWORD>(c_values), reinterpret_cast<LPDWORD>(cch_valueName_max), reinterpret_cast<LPDWORD>(cb_value_data_max), reinterpret_cast<LPDWORD>(cb_security_descriptor_max), time_last_write);
00343 }
00344
00345 static result_type reg_enum_key( hkey_type hkey,
00346 ws_dword_t index,
00347 char_type* key_name,
00348 size_type* cch_key_name,
00349 time_type* time_last_write = NULL)
00350 {
00351 return ::RegEnumKeyExA(hkey, index, key_name, reinterpret_cast<LPDWORD>(cch_key_name), NULL, NULL, NULL, time_last_write);
00352 }
00353
00354 static result_type reg_enum_key( hkey_type hkey,
00355 ws_dword_t index,
00356 char_type* key_name,
00357 size_type* cch_key_name,
00358 char_type* key_class,
00359 size_type* cch_key_class,
00360 time_type* time_last_write)
00361 {
00362 return ::RegEnumKeyExA(hkey, index, key_name, reinterpret_cast<LPDWORD>(cch_key_name), NULL, key_class, reinterpret_cast<LPDWORD>(cch_key_class), time_last_write);
00363 }
00364
00365 static result_type reg_enum_value( hkey_type hkey,
00366 ws_dword_t index,
00367 char_type* valueName,
00368 size_type* cch_valueName,
00369 ws_dword_t* valueType,
00370 void* data,
00371 size_type &cbData)
00372 {
00373 return ::RegEnumValueA(hkey, index, valueName, reinterpret_cast<LPDWORD>(cch_valueName), NULL, valueType, reinterpret_cast<LPBYTE>(data), reinterpret_cast<LPDWORD>(&cbData));
00374 }
00375
00376 static result_type reg_enum_value( hkey_type hkey,
00377 ws_dword_t index,
00378 char_type* valueName,
00379 size_type* cch_valueName)
00380 {
00381 return ::RegEnumValueA(hkey, index, valueName, reinterpret_cast<LPDWORD>(cch_valueName), NULL, NULL, NULL, NULL);
00382 }
00383
00384 private:
00385 static result_type execute_dynamic_(
00386 ws_char_a_t const* module
00387 , ws_char_a_t const* function
00388 , hkey_type a1
00389 , char_type const* a2
00390 )
00391 {
00392 result_type r = ERROR_SUCCESS;
00393 HINSTANCE hinst = ::LoadLibraryA(module);
00394
00395 if(NULL == hinst)
00396 {
00397 r = static_cast<result_type>(::GetLastError());
00398 }
00399 else
00400 {
00401 union
00402 {
00403 FARPROC fp;
00404 DWORD (STLSOFT_STDCALL* pfn)(HKEY, LPCSTR);
00405 } u;
00406
00407 u.fp = ::GetProcAddress(hinst, function);
00408
00409 if(NULL == u.fp)
00410 {
00411 r = static_cast<result_type>(::GetLastError());
00412 }
00413 else
00414 {
00415 r = static_cast<result_type>((*u.pfn)(a1, a2));
00416 }
00417
00418 ::FreeLibrary(hinst);
00419 }
00420
00421 return r;
00422 }
00423 };
00424
00425 STLSOFT_TEMPLATE_SPECIALISATION
00426 struct reg_traits<ws_char_w_t>
00427 : public system_traits<ws_char_w_t>
00428 {
00429 public:
00430 typedef ws_char_w_t char_type;
00431 typedef ws_size_t size_type;
00432 typedef ws_ptrdiff_t difference_type;
00433 typedef HKEY hkey_type;
00434 typedef reg_string_w_t string_type;
00435 typedef FILETIME time_type;
00436 typedef LONG result_type;
00437
00438 public:
00439 static hkey_type key_dup(hkey_type hkey, REGSAM samDesired, result_type *result = NULL)
00440 {
00441 return reg_dup_key(hkey, samDesired, result);
00442 }
00443 static hkey_type reg_dup_key(hkey_type hkey, REGSAM samDesired, result_type *result = NULL)
00444 {
00445 hkey_type hkeyDup;
00446 result_type res = ::RegOpenKeyExW(hkey, L"", 0, samDesired, &hkeyDup);
00447
00448 if(ERROR_SUCCESS != res)
00449 {
00450 hkeyDup = NULL;
00451 }
00452
00453 if(NULL != result)
00454 {
00455 *result = res;
00456 }
00457
00458 return hkeyDup;
00459 }
00460
00461 static result_type reg_open_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, REGSAM samDesired = KEY_ALL_ACCESS)
00462 {
00463 return ::RegOpenKeyExW(hkey, sub_key_name, 0, samDesired, hkey_result);
00464 }
00465
00466 static result_type reg_create_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, REGSAM samDesired = KEY_ALL_ACCESS)
00467 {
00468 return ::RegCreateKeyExW(hkey, sub_key_name, 0, NULL, 0, samDesired, NULL, hkey_result, NULL);
00469 }
00470
00471 static result_type reg_create_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, ws_bool_t &bCreated, REGSAM samDesired = KEY_ALL_ACCESS)
00472 {
00473 DWORD disposition;
00474 result_type res = ::RegCreateKeyExW(hkey, sub_key_name, 0, NULL, 0, samDesired, NULL, hkey_result, &disposition);
00475
00476 bCreated = (ERROR_SUCCESS == res) && (REG_CREATED_NEW_KEY == disposition);
00477
00478 return res;
00479 }
00480
00481 static result_type reg_delete_key(hkey_type hkey, char_type const* sub_key_name)
00482 {
00483 return ::RegDeleteKeyW(hkey, sub_key_name);
00484 }
00485
00486 static result_type reg_query_value(hkey_type hkey, char_type const* valueName, ws_dword_t& valueType, void* data, size_type &cbData)
00487 {
00488 return ::RegQueryValueExW(hkey, valueName, NULL, &valueType, static_cast<LPBYTE>(data), reinterpret_cast<LPDWORD>(&cbData));
00489 }
00490
00491 static result_type reg_set_value(hkey_type hkey, char_type const* valueName, ws_dword_t valueType, void const* data, size_type cbData)
00492 {
00493 return ::RegSetValueExW(hkey, valueName, 0, valueType, static_cast<BYTE const*>(data), static_cast<DWORD>(cbData));
00494 }
00495
00496 static result_type reg_delete_value(hkey_type hkey, char_type const* valueName)
00497 {
00498 return ::RegDeleteValueW(hkey, valueName);
00499 }
00500
00501 static result_type reg_delete_tree(
00502 hkey_type hkey
00503 , char_type const* sub_key_name
00504 )
00505 {
00506 result_type res = execute_dynamic_("advapi32.dll", "RegDeleteTreeW", hkey, sub_key_name);
00507
00508 if(ERROR_PROC_NOT_FOUND == res)
00509 {
00510 res = execute_dynamic_("shlwapi.dll", "SHDeleteKeyW", hkey, sub_key_name);
00511 }
00512
00513 return res;
00514 }
00515
00516 static result_type reg_query_info( hkey_type hkey,
00517 char_type* key_class,
00518 size_type* cch_key_class,
00519 ws_uint32_t* c_sub_keys,
00520 size_type* cch_sub_key_max,
00521 size_type* cch_key_class_max,
00522 ws_uint32_t* c_values,
00523 size_type* cch_valueName_max,
00524 size_type* cb_value_data_max,
00525 size_type* cb_security_descriptor_max,
00526 time_type* time_last_write)
00527 {
00528 if( NULL == cch_key_class &&
00529 NULL != key_class)
00530 {
00531 return ERROR_INVALID_PARAMETER;
00532 }
00533
00534 return ::RegQueryInfoKeyW(hkey, key_class, reinterpret_cast<LPDWORD>(cch_key_class), NULL, reinterpret_cast<LPDWORD>(c_sub_keys), reinterpret_cast<LPDWORD>(cch_sub_key_max), reinterpret_cast<LPDWORD>(cch_key_class_max), reinterpret_cast<LPDWORD>(c_values), reinterpret_cast<LPDWORD>(cch_valueName_max), reinterpret_cast<LPDWORD>(cb_value_data_max), reinterpret_cast<LPDWORD>(cb_security_descriptor_max), time_last_write);
00535 }
00536
00537 static result_type reg_enum_key( hkey_type hkey,
00538 ws_dword_t index,
00539 char_type* key_name,
00540 size_type* cch_key_name,
00541 time_type* time_last_write = NULL)
00542 {
00543 return ::RegEnumKeyExW(hkey, index, key_name, reinterpret_cast<LPDWORD>(cch_key_name), NULL, NULL, NULL, time_last_write);
00544 }
00545
00546 static result_type reg_enum_key( hkey_type hkey,
00547 ws_dword_t index,
00548 char_type* key_name,
00549 size_type* cch_key_name,
00550 char_type* key_class,
00551 size_type* cch_key_class,
00552 time_type* time_last_write)
00553 {
00554 return ::RegEnumKeyExW(hkey, index, key_name, reinterpret_cast<LPDWORD>(cch_key_name), NULL, key_class, reinterpret_cast<LPDWORD>(cch_key_class), time_last_write);
00555 }
00556
00557 static result_type reg_enum_value( hkey_type hkey,
00558 ws_dword_t index,
00559 char_type* valueName,
00560 size_type* cch_valueName,
00561 ws_dword_t* valueType,
00562 void* data,
00563 size_type &cbData)
00564 {
00565 return ::RegEnumValueW(hkey, index, valueName, reinterpret_cast<LPDWORD>(cch_valueName), NULL, valueType, reinterpret_cast<LPBYTE>(data), reinterpret_cast<LPDWORD>(&cbData));
00566 }
00567
00568 static result_type reg_enum_value( hkey_type hkey,
00569 ws_dword_t index,
00570 char_type* valueName,
00571 size_type* cch_valueName)
00572 {
00573 return ::RegEnumValueW(hkey, index, valueName, reinterpret_cast<LPDWORD>(cch_valueName), NULL, NULL, NULL, NULL);
00574 }
00575
00576 private:
00577 static result_type execute_dynamic_(
00578 ws_char_a_t const* module
00579 , ws_char_a_t const* function
00580 , hkey_type a1
00581 , char_type const* a2
00582 )
00583 {
00584 result_type r = ERROR_SUCCESS;
00585 HINSTANCE hinst = ::LoadLibraryA(module);
00586
00587 if(NULL == hinst)
00588 {
00589 r = static_cast<result_type>(::GetLastError());
00590 }
00591 else
00592 {
00593 union
00594 {
00595 FARPROC fp;
00596 DWORD (STLSOFT_STDCALL* pfn)(HKEY, LPCWSTR);
00597 } u;
00598
00599 u.fp = ::GetProcAddress(hinst, function);
00600
00601 if(NULL == u.fp)
00602 {
00603 r = static_cast<result_type>(::GetLastError());
00604 }
00605 else
00606 {
00607 r = static_cast<result_type>((*u.pfn)(a1, a2));
00608 }
00609
00610 ::FreeLibrary(hinst);
00611 }
00612
00613 return r;
00614 }
00615
00616 };
00617
00618 #endif
00619
00620
00621
00622 #ifndef _WINSTL_NO_NAMESPACE
00623 # if defined(_STLSOFT_NO_NAMESPACE) || \
00624 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00625 }
00626 # else
00627 }
00628 }
00629 # endif
00630 #endif
00631
00632
00633
00634 #endif
00635
00636