zoukankan      html  css  js  c++  java
  • c++读取REG_MULTI_SZ类型注册表

    First: run RegQueryValueEx to get type and necessary memory size:

    Single byte code:

     1 DWORD type, size;
     2 vector<string> target;
     3 if ( RegQueryValueExA(
     4     your_key, // HKEY
     5     TEXT("ValueName"),
     6     NULL,
     7     &type,
     8     NULL,
     9     &size ) != ERROR_SUCCESS )
    10   return;
    11 if ( type == REG_MULTI_SZ )
    12 {
    13   vector<char> temp(size);
    14 
    15   if ( RegQueryValueExA(
    16       your_key, // HKEY
    17       TEXT("ValueName"),
    18       NULL,
    19       NULL,
    20       reinterpret_cast<LPBYTE>(&temp[0]),
    21       &size ) != ERROR_SUCCESS )
    22   return;
    23 
    24   size_t index = 0;
    25   size_t len = strlen( &temp[0] );
    26   while ( len > 0 )
    27   {
    28     target.push_back(&temp[index]);
    29     index += len + 1;
    30     len = strlen( &temp[index] );
    31   }
    32 }

    Unicode:

     1 DWORD type, size;
     2 vector<wstring> target;
     3 if ( RegQueryValueExW(
     4     your_key, // HKEY
     5     TEXT("ValueName"),
     6     NULL,
     7     &type,
     8     NULL,
     9     &size ) != ERROR_SUCCESS )
    10   return;
    11 if ( type == REG_MULTI_SZ )
    12 {
    13   vector<wchar_t> temp(size/sizeof(wchar_t));
    14 
    15   if ( RegQueryValueExW(
    16       your_key, // HKEY
    17       TEXT("ValueName"),
    18       NULL,
    19       NULL,
    20       reinterpret_cast<LPBYTE>(&temp[0]),
    21       &size ) != ERROR_SUCCESS )
    22   return;
    23 
    24   size_t index = 0;
    25   size_t len = wcslen( &temp[0] );
    26   while ( len > 0 )
    27   {
    28     target.push_back(&temp[index]);
    29     index += len + 1;
    30     len = wcslen( &temp[index] );
    31   }
    32 }
  • 相关阅读:
    链表
    链式学习法:提升技术深度
    数组
    写点什么
    7 天掌握算法面试必考知识点: 作业安排及如何提交
    创建Mac OS root账户
    正则表达式匹配及替换
    Xcode 10 之New Build System & Legacy Build System 旧版构建系统
    性能指标:TPS、QPS、RT、吞吐量
    Objective-C和Swift语言特性
  • 原文地址:https://www.cnblogs.com/davygeek/p/5286193.html
Copyright © 2011-2022 走看看