[英]C++ read registry string value in char*
I'm reading a registry value like this: 我正在读取这样的注册表值:
char mydata[2048];
DWORD dataLength = sizeof(mydata);
DWORD dwType = REG_SZ;
..... open key, etc
ReqQueryValueEx(hKey, keyName, 0, &dwType, (BYTE*)mydata, &dataLength);
My problem is, that after this, mydata content looks like: [63, 00, 3A, 00, 5C, 00...], ie this looks like a unicode?!?!. 我的问题是,在此之后,mydata内容看起来像:[63,00,3A,00,5C,00 ...],即,看起来像是unicode?!?!。
I need to convert this somehow to be a normal char array, without these [00], as they fail a simple logging function I have. 我需要以某种方式将其转换为普通的char数组,而没有这些[00],因为它们无法通过我拥有的简单日志记录功能。 Ie if I call like this: WriteMessage(mydata), it outputs only "c", which is the first char in the registry.
即,如果我这样调用:WriteMessage(mydata),它将仅输出“ c”,这是注册表中的第一个字符。 I have calls to this logging function all over the place, so I'd better of not modify it, but somehow "fix" the registry value.
我到处都在调用此日志记录功能,因此最好不要对其进行修改,而应以某种方式“修复”注册表值。 Here is the log function:
这是日志功能:
void Logger::WriteMessage(const char *msg)
{
time_t now = time(0);
struct tm* tm = localtime(&now);
std::ofstream logFile;
logFile.open(filename, std::ios::out | std::ios::app);
if ( logFile.is_open() )
{
logFile << tm->tm_mon << '/' << tm->tm_mday << '/' << tm->tm_year << ' ';
logFile << tm->tm_hour << ':' << tm->tm_min << ':' << tm->tm_sec << "> ";
logFile << msg << "\n";
logFile.close();
}
}
查看WideCharToMultiByte ()。
You have two solutions here: 您在这里有两种解决方案:
wchar_t mydata[2048];
wchar_t mydata[2048];
. RegQueryValueExA()
if performance in this area is not your concern. RegQueryValueExA()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.