qt中unicode的使用 以及微软unicode函数的使用
2008-11-11 20:33
351 查看
在公司做的一个项目,需要读写注册表.在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();
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();
相关文章推荐
- Qt简介以及如何配置Qt使用VS2010进行开发
- qt中如何由Double类型变为QString类型以及chop()的使用
- (转)Qt中如何使用样式表QPalette以及相关注意事项
- QT中使用 slot 传递 opencv 中得Mat对象以及 使用多线程集成开源代码。
- QT 国际化和本地化,附上实际案例以及一些使用心得和注意点
- 一起谈.NET技术,Qt简介以及如何配置Qt使用VS2010进行开发
- Qt简介以及如何配置Qt使用VS2010进行开发
- QT布局以及使用QSS
- vs2013中配置Qt的方法以及使用感受。
- 关于Qt的事件循环以及QEventLoop的简单使用
- Qt简介以及如何配置Qt使用VS2010进行开发
- Qt中如何使用样式表QPalette以及相关注意事项
- Qt简介以及如何配置Qt使用VS2010进行开发
- 财富500强的前10个公司里有8个公司在使用Qt(Qt自己认为的优点是:直觉主义、跨平台、节省时间),以及一些商业案例
- Ubuntu 14.04 + QT 计算器开发实例1-----全局变量的使用以及double、字符串类型互转
- Qt中如何使用样式表QPalette以及相关注意事项
- 使用opencv2在qt界面上进行摄像头采集以及简单的拍照功能
- Qt实现areo毛玻璃效果的类,以及使用方法:
- CString 与 char * 和 const char*的转换,以及在Unicode项目中的使用.
- 7-干货! QT -实现使用拖放打开文件,以及打开可拖动的图片