从注册表中提取REG_MULTI_SZ值并存储在字符串数组中
visual studio 2010 - Extract REG_MULTI_SZ value from registry and store in string array c++
有一个REG_MULTI_SZ值,我想把它放在字符串数组中,以便我的程序可以用它们做其他事情。我从来没有使用过c++来访问注册表,所以我有点迷失了以下一些例子。我用的是VS10。
是否有简单的方法来做到这一点?谢谢。
首先:运行RegQueryValueEx
获取类型和所需的内存大小:
单字节码:
DWORD type, size;
vector<string> target;
if ( RegQueryValueExA(
your_key, // HKEY
TEXT("ValueName"),
NULL,
&type,
NULL,
&size ) != ERROR_SUCCESS )
return;
if ( type == REG_MULTI_SZ )
{
vector<char> temp(size);
if ( RegQueryValueExA(
your_key, // HKEY
TEXT("ValueName"),
NULL,
NULL,
reinterpret_cast<LPBYTE>(&temp[0]),
&size ) != ERROR_SUCCESS )
return;
size_t index = 0;
size_t len = strlen( &temp[0] );
while ( len > 0 )
{
target.push_back(&temp[index]);
index += len + 1;
len = strlen( &temp[index] );
}
}
Unicode: DWORD type, size;
vector<wstring> target;
if ( RegQueryValueExW(
your_key, // HKEY
TEXT("ValueName"),
NULL,
&type,
NULL,
&size ) != ERROR_SUCCESS )
return;
if ( type == REG_MULTI_SZ )
{
vector<wchar_t> temp(size/sizeof(wchar_t));
if ( RegQueryValueExW(
your_key, // HKEY
TEXT("ValueName"),
NULL,
NULL,
reinterpret_cast<LPBYTE>(&temp[0]),
&size ) != ERROR_SUCCESS )
return;
size_t index = 0;
size_t len = wcslen( &temp[0] );
while ( len > 0 )
{
target.push_back(&temp[index]);
index += len + 1;
len = wcslen( &temp[index] );
}
}
相关文章:
- 我的目标是编写一个程序来计算和存储字符串在字符数组中出现的位置
- 在向量 C++14(无限制联合)的结构内的联合中创建和存储字符串
- 如何存储字符串列表
- 在向量中存储字符串存在 SEG 错误
- 指针存储字符串?
- 逐个字母存储字符串并打印
- 将字符数组转换为字符串并存储字符串?
- 当分配动态内存以存储字符串副本时,程序会中断
- 在C/C++中存储字符串、数组和指针,哪种方法更有效
- 我们如何以 7 位格式存储字符串
- C 存储字符串输入为CString
- TVItem lparam存储字符串
- C++以相反的顺序存储字符串
- 如果存储字符串的char数组小于字符串,则C++实际存储字符串
- 为什么我的 SetBookTitle 不存储字符串
- 如何在 C 中有效地存储字符串的映射
- 如何使用好友运算符存储字符串
- 如何在 C++ 中存储字符串和整数串联的变量
- 如何在 c++ 中存储字符串数组
- 存储字符串