Home > Software engineering >  Using RegSetValueExA and writing this book table RegSetValueExW garbled words (in Chinese)
Using RegSetValueExA and writing this book table RegSetValueExW garbled words (in Chinese)

Time:09-19

To write in Chinese, the registry in a machine running normally, using RegSetValueExA and RegSetValueExW are normal, on another machine, RegSetValueExA and RegSetValueExW, garbled words, this is how to return a responsibility, what a great god help me answer the

Bool SetRegValue (hkeys root, const LPCSTR regPath, const LPCSTR name, const string strReadRes, dwords dwAccess)
{
Hkeys hkeys;
WCHAR szLocation [MAX_PATH]={0};
DWORD dwSize=sizeof (DWORD);
DWORD dwType=REG_SZ;
LONG ret.

Ret=RegOpenKeyExA (root, regPath, 0, dwAccess, & amp; Hkeys);
DWORD len=strReadRes. The size ();

If (ret==ERROR_SUCCESS) {
If (ERROR_SUCCESS==RegSetValueExA (hkeys, name, 0, REG_SZ, (CONST BYTE *) strReadRes. C_str (), len + 1)) {
RegCloseKey (hkeys);
return true;
}
}
RegCloseKey (hkeys);
return false;
}

Bool SetRegValueW (hkeys root, LPCWSTR regPath, LPCWSTR name, const wstring wstrReadRes, dwords dwAccess)
{
Hkeys hkeys;
WCHAR szLocation [MAX_PATH]={0};
DWORD dwSize=sizeof (DWORD);
DWORD dwType=REG_SZ;
LONG ret.

Ret=RegOpenKeyExW (root, regPath, 0, dwAccess, & amp; Hkeys);
DWORD len=wstrReadRes. The size () * 2;

If (ret==ERROR_SUCCESS) {
If (ERROR_SUCCESS==RegSetValueEx (hkeys, name, 0, REG_SZ, (CONST BYTE *) wstrReadRes. C_str (), len + 1)) {
RegCloseKey (hkeys);
return true;
}
}
RegCloseKey (hkeys);
return false;
}

CodePudding user response:

Why nobody reply, your top

CodePudding user response:

Read registry:
Bool CRegedit: : ReadRegValueW (hkeys root, LPCWSTR regPath, LPCWSTR name, wstring& StrReadRes, dwords dwAccess)
{
Hkeys hkeys;
WCHAR szLocation [MAX_PATH]={0};
DWORD dwSize=sizeof (DWORD);
DWORD dwType=REG_SZ;
LONG ret.

Ret=RegOpenKeyEx (root, regPath, 0, dwAccess, & amp; Hkeys);
If (ret==ERROR_SUCCESS) {
RegQueryValueEx (hkeys, name, 0, & amp; DwType, NULL, & amp; DwSize);
Ret=RegQueryValueEx (hkeys, name, 0, & amp; DwType, (LPBYTE) & amp; SzLocation, & amp; DwSize);
If (ret==ERROR_SUCCESS) {
StrReadRes=STD: : wstring (szLocation);
RegCloseKey (hkeys);
return true;
}
}
RegCloseKey (hkeys);
return false;
}


Bool CRegedit: : ReadRegValue (hkeys root, LPCSTR regPath, LPCSTR name, string& StrReadRes, dwords dwAccess)
{
Hkeys hkeys;
WCHAR szLocation [MAX_PATH]={0};
DWORD dwSize=sizeof (DWORD);
DWORD dwType=REG_SZ;
LONG ret.

Ret=RegOpenKeyExA (root, regPath, 0, dwAccess, & amp; Hkeys);
If (ret==ERROR_SUCCESS) {
RegQueryValueExA (hkeys, name, 0, & amp; DwType, NULL, & amp; DwSize);
Ret=RegQueryValueExA (hkeys, name, 0, & amp; DwType, (LPBYTE) & amp; SzLocation, & amp; DwSize);
If (ret==ERROR_SUCCESS) {
StrReadRes=WStringToString (szLocation);
RegCloseKey (hkeys);
return true;
}
}
RegCloseKey (hkeys);
return false;
}

CodePudding user response:

I write is formatted string colon as a delimiter (English) : the software name + English + colon colon + integer, integer, (on one machine) to write this book table is garbled, using ReadRegValueW read at the same time, some can read the Chinese characters, and some can't read Chinese characters, such as "Internet explorer: 2345:10", words can't read it out, also can't read the colon, but "iQIYI video: 2345:10", characters and colon can read (even check the registry is the code), which is master for character encoding help solve it?

CodePudding user response:

The individual estimates is appeared on the code conversion
StrReadRes=STD: : wstring (szLocation);
StrReadRes=WStringToString (szLocation);

Suggest write UNICODE transformation into UTF8, read UTF8 to UNICODE

  • Related