CString UTF8ToUni(char* UTF8)
{
DWORD dwUnicodeLen; //转换后Unicode的长度
TCHAR *pwText; //保存Unicode的指针
CString strUnicode; //返回值
//获得转换后的长度,并分配内存
dwUnicodeLen = MultiByteToWideChar(CP_UTF8,0,UTF8,-1,NULL,0);
pwText = new TCHAR[dwUnicodeLen];
if (!pwText)
{
return strUnicode;
}
//转为Unicode
MultiByteToWideChar(CP_UTF8,0,UTF8,-1,pwText,dwUnicodeLen);
//转为CString
strUnicode.Format(_T("%s"),pwText);
//清除内存
delete []pwText;
//返回转换好的Unicode字串
return strUnicode;
}
void TestSQLite()
{
CString sTitle;
int iRet=0;
const char* sDbName=("history");
if (SQLITE_OK==sqlite3_open(sDbName,&m_conn))
{
const char* sSQL=("SELECT * FROM BOOKMARK ");
if (SQLITE_OK==sqlite3_prepare_v2(m_conn,sSQL,strlen(sSQL),&m_stmt,NULL))
{
iRet=sqlite3_step(m_stmt);
while (SQLITE_ROW==iRet)
{
const unsigned char* ansiTitle=sqlite3_column_text(m_stmt,1);
sTitle=UTF8ToUni((char*)ansiTitle);
MessageBox(sTitle);
iRet=sqlite3_step(m_stmt);
}
sqlite3_finalize(m_stmt);
}
sqlite3_close(m_conn);
}
}
SQLite 简单用法
最新推荐文章于 2024-07-30 18:34:10 发布