|
- int MAX_SIZE = 256;
- HKEY hKey1;
- wchar_t *key1Value = L"abc";//这里写成中文结果也相同
- char *key1buf = new char[MAX_SIZE];
-
- memset(key1buf,0,MAX_SIZE);
- int size = 0;//得到转换的字节数是3
- size = wcstombs(key1buf,key1Value,MAX_SIZE);
- key1buf[size] = '\0';
-
- DWORD keyReturn;
- long hResult = 0;
- hResult = RegCreateKeyEx(HKEY_CLASSES_ROOT,TEXT("mypro"),0,TEXT("REG_NONE"),REG_OPTION_NON_VOLATILE,0,NULL, &hKey1,&keyReturn);
- if(hResult == ERROR_SUCCESS )
- {
- hResult = RegSetValueEx(hKey1,TEXT("Default"),0,REG_SZ,(byte *)key1buf, strlen(key1buf)+1);
- if(hResult == ERROR_SUCCESS)
- {
- MessageBox(NULL,TEXT("mypro Created Successfully"),TEXT("Message"),MB_OK);
- }
- }
- RegCloseKey(hKey1);
- delete[] key1buf;
复制代码
以上是完整的代码,编译正常通过,但是在实际执行之后,比如写入123,得到的结果就是1和2被解释成了乱码,3还在,检查了很久也没想通到底是哪里的问题,宽字符转换到字节,大小不是应该增大的吗,为什么还是和原来的大小相同,麻烦高手帮忙,谢谢!
|
|