将gbk字符串转换成utf-8,存储到注册表中后,再次从注册表读取转换成gbk,有问题!!!
char *a = "新2新"; printf("gbk:'%s'\n", a); int ii; for(ii = 0; ii < strlen(a); ii++) { printf("0x%0x ", (BYTE)a[ii]); } printf("\n\n"); char b[1024] = {0}; size_t tt; toUTF8(a, b, 1024, &tt); printf("utf-8:'%s'\n", b); printf("tt:%d\n\n", tt); setRegeditConfig_STR(HKEY_CURRENT_USER, REG_SOFT_KEY, key_file_dlg_choose_logo, b, tt + 1); //int ii; for(ii = 0; ii < tt; ii++) { printf("0x%0x ", (BYTE)b[ii]); } printf("\n\n"); unsigned long readLen = MAX_PATH; char filePath[MAX_PATH] = {0}; if(getRegeditConfig_STR(HKEY_CURRENT_USER, REG_SOFT_KEY, key_file_dlg_choose_logo, filePath, &readLen)) { printf("filePath:'%s'\n", filePath); printf("len-utf8:%d\n\n", readLen); int ii; for(ii = 0; ii < readLen; ii++) { printf("0x%0x ", (BYTE)filePath[ii]); } printf("\n\n"); char *p = utf8ToGBK(filePath, &tt); printf("filePath-gbk:'%s'\n", p); printf("len-gbk:%d\n", tt); //int ii; for(ii = 0; ii < tt; ii++) { printf("0x%0x ", (BYTE)b[ii]); } printf("\n"); } system("pause"); exit(0);
char *a = "新新2新"; printf("gbk:'%s'\n", a); int ii; for(ii = 0; ii < strlen(a); ii++) { printf("0x%0x ", (BYTE)a[ii]); } printf("\n\n"); char b[1024] = {0}; size_t tt; toUTF8(a, b, 1024, &tt); printf("utf-8:'%s'\n", b); printf("tt:%d\n\n", tt); setRegeditConfig_STR(HKEY_CURRENT_USER, REG_SOFT_KEY, key_file_dlg_choose_logo, b, tt + 1); //int ii; for(ii = 0; ii < tt; ii++) { printf("0x%0x ", (BYTE)b[ii]); } printf("\n\n"); unsigned long readLen = MAX_PATH; char filePath[MAX_PATH] = {0}; if(getRegeditConfig_STR(HKEY_CURRENT_USER, REG_SOFT_KEY, key_file_dlg_choose_logo, filePath, &readLen)) { printf("filePath:'%s'\n", filePath); printf("len-utf8:%d\n\n", readLen); int ii; for(ii = 0; ii < readLen; ii++) { printf("0x%0x ", (BYTE)filePath[ii]); } printf("\n\n"); char *p = utf8ToGBK(filePath, &tt); printf("filePath-gbk:'%s'\n", p); printf("len-gbk:%d\n", tt); //int ii; for(ii = 0; ii < tt; ii++) { printf("0x%0x ", (BYTE)b[ii]); } printf("\n"); } system("pause"); exit(0);