問題はRegEnumValue()
とは関係ありません。
アプリはUNICODE
がコンパイル時に定義されているかどうかに応じて、実際にどちらかRegQueryValueExA()
(ANSI)またはRegQueryValueExW()
(ユニコード)にマッププリプロセッサマクロである、TCHAR
ベースRegQueryValueEx()
を呼んでいます。
RegQueryValueExW()
は、文字列データをUTF-16LE形式のUnicodeテキストとして返します。これは、バッファに表示されているとおりです。したがって、アプリケーションはUnicode用にコンパイルされています。あなたが見ているのは、完全に正常な動作です。
だから、あなたはそれがあなたに与えられている形式で、例えば、文字列データを処理する必要があります。
BYTE byteArray[MAX];
DWORD dataSize = sizeof(byteArray);
DWORD type = 0;
if (RegQueryValueEx(// <-- calling the TCHAR version!
hKey,
subKey,
nullptr,
&type,
reinterpret_cast<BYTE*>(&byteArray),
&dataSize) == 0)
{
switch (type)
{
case REG_DWORD:
{
LPDWORD value = reinterpret_cast<LPDWORD>(&byteArray);
// use *value as needed ...
break;
}
case REG_SZ:
case REG_MULTI_SZ:
case REG_EXPAND_SZ:
{
// note the T in LPTSTR! That means 'TCHAR' is used...
LPTSTR text = reinterpret_cast<LPTSTR>(&byteArray);
// use text as needed, up to (dataSize/sizeof(TCHAR)) number
// of TCHARs. This is because RegQueryValueEx() does not
// guarantee the output data has a null terminator. If you
// want that, use RegGetValue() instead...
break;
}
}
}
または:
BYTE byteArray[MAX];
DWORD dataSize = sizeof(byteArray);
DWORD type = 0;
if (RegQueryValueExW(// <-- calling the UNICODE version!
hKey,
subKey,
nullptr,
&type,
reinterpret_cast<BYTE*>(&byteArray),
&dataSize) == 0)
{
switch (type)
{
case REG_DWORD:
{
LPDWORD value = reinterpret_cast<LPDWORD>(&byteArray);
// use *value as needed ...
break;
}
case REG_SZ:
case REG_MULTI_SZ:
case REG_EXPAND_SZ:
{
// note the W in LPWSTR! That means 'WCHAR' is used...
LPWSTR text = reinterpret_cast<LPWSTR>(&byteArray);
// use text as needed, up to (dataSize/sizeof(WCHAR)) number
// of WCHARs. This is because RegQueryValueExW() does not
// guarantee the output data has a null terminator. If you
// want that, use RegGetValueW() instead...
break;
}
}
}
あなたが別の形式でテキストをしたい場合、あなたは意志
などWideCharToMultiByte()
やequiviと同様に、Unicodeとしてそれを読んだ後、それを変換します。どちらかしなければなりません貸してください。
は、ドキュメントごとに、ユーザーの現在のロケールで、ANSIテキストとして文字列データを返します。これは、直接RegQueryValueExA()
(またはRegGetValueA()
)を使用します。
データはREG_SZ
、REG_MULTI_SZ
またはREG_EXPAND_SZ
タイプを持っている場合、およびこの関数のANSIバージョンが使用されます(RegQueryValueExA
を明示的に呼び出すか、またはWindows.h
ファイルを含める前にUNICODE
を定義しない)、この関数は格納されたUnicode文字列をANSI文字列に変換してからlpData
が指すバッファにコピーします。
BYTE byteArray[MAX];
DWORD dataSize = sizeof(byteArray);
DWORD type = 0;
if (RegQueryValueExA(// <-- calling the ANSI version
hKey,
subKey,
nullptr,
&type,
reinterpret_cast<BYTE*>(&byteArray),
&dataSize) == 0)
{
switch (type)
{
case REG_DWORD:
{
LPDWORD value = reinterpret_cast<LPDWORD>(&byteArray);
// use *value as needed ...
break;
}
case REG_SZ:
case REG_MULTI_SZ:
case REG_EXPAND_SZ:
{
// note the lack of T in LPSTR! That means 'char' is used...
LPSTR text = reinterpret_cast<LPSTR>(&byteArray);
// use text as needed, up to dataSize number of chars. This
// is because RegQueryValueExA() does not guarantee the
// output data has a null terminator. If you want that,
// use RegGetValueA() instead...
break;
}
}
}
いずれかの方法では、ちょうどあなたがに変換することを決定し、ターゲット文字セットに存在しない任意の非ASCII文字を失う危険を冒すことに注意してください。したがって、代わりにUnicodeを使用し、バッファデータをWCHAR
データ(UNICODE
が定義されているときにはTCHAR
にマップされているもの)として扱うほうがよい。
あなたは何を求めていますか? – RbMm
Unicode UTF16-LEが16bitで終わる0 –