qt中unicode的使用 以及微软unicode函数的使用

在公司做的一个项目,需要读写注册表.在unicode 处理方面费了不少时间,好不容易搞定,结果被我用以前的结点工程覆盖掉,只好返工重来,结果耗了更多的时间,反复的碰壁,不得不让我对这方面有了些领悟: int GetReg(QString &StrIp,float& atten) { HKEY hKey; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,L"SOFTWARE//spgt",NULL,KEY_ALL_ACCESS,&hKey) != ERROR_SUCCESS) return FUNC_ERROR; DWORD KeyIndex = 0; LPTSTR lpValueName =new TCHAR[250]; // LPTSTR alternative between LPSTR and LPWSTR,which depends on whether "UNICODE" has been defined DWORD* lpcValueName = new DWORD; //specify the length of ValueName in "TCHAR" *lpcValueName = 250; LPDWORD lpdType = new DWORD; LPBYTE lpData = new BYTE[1024];//used to get the value of the entry specified by "ValueName" LPDWORD lpcData = new DWORD;// in/out size of lpdata in Bytes(When the lpdata is a unicode array,it also includes the null-Character) *lpcData = 1024; int iflag = 0; while(RegEnumValue(hKey,KeyIndex++,lpValueName,lpcValueName,NULL,lpdType,lpData,lpcData) == ERROR_SUCCESS) { if(lstrcmp(lpValueName,L"ip") == 0) //"L" convert the string from ascii to unicode lstrcmp means an alternative function between lstrcmpA and lstrcmpW { // it depends on whether you have defined macro "UNICODE" which is predefined by MicroSoft.It is different from "_UNICODE" which is provided by c/c++ run-time libary StrIp = QString((QChar*)lpData,(*lpcData)/2-1); // Convert a unicode array to a string iflag++; } if(lstrcmp(lpValueName,L"Level") == 0) { QString str = QString((QChar*)lpData,(*lpcData)/2-1); bool iOk = false; atten = str.toFloat(&iOk); if(iOk == false) { RegCloseKey(hKey); return FUNC_ERROR; } iflag++; } *lpcData = 1024; *lpcValueName = 250; } if(iflag != 2) { RegCloseKey(hKey); return FUNC_ERROR; } return FUNC_SUCCESS; } 另; 从Qstring转换成Unicode数组 BYTE* unicode = (BYTE*) QString("test").unicode();
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值