查看单个帖子
旧 2009-05-05, 12:14 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】how can i convert odstring to cstring

how can i convert odstring to cstring?
how can i convert odstring to cstring?
hi, i'm david.lee
following codes is right? comparenocase function couldn't operate normally.
please help me.
------------------------------------------------------------------------
odstring typeface;
pstyle->font(typeface, bold, italic, charset, pitchandfamily);
cstring s;
for (int i = 0; i < m_ctrlttffont.getitemcount(); i++)
{
m_ctrlttffont.getlbtext(i, s);
if (!s.comparenocase(typeface.c_str()))
break;
}
------------------------------------------------------------------------
the code looks right, yes.(for unicode)
instead of .c_str() you may also use type cast operator, like (const tchar*)
(to support both unicode, and non-unicode configurations)
vladimir
thank you for sincerly reply.
i didn't understand which code is error.
converting cstring to odstring is ok. but the problem is finded in charformat structure (tchar szfacename[lf_facesize])
and i solved this problem as like following code.
1. convert from cstring to tchar szfacename[lf_facesize] in unicode
#include <atlconv.h>
uses_conversion;
cstring s;
m_ctrlttffont.getwindowtext(s);
lstrcpya(m_charformat.szfacename, t2a((lptstr)(lpctstr)s));
2. convert from tchar szfacename[lf_facesize] to odstring or cstring in unicode
#include <atlconv.h>
uses_conversion;
odstring szname;
szname.format(_t("%s"), a2t(m_charformat.szfacename));
anyway, thank you for sincely reply.
if you are supporting unicode only, why use t2a?
if you support both configurations, when the previous question applies, and besides odstring::format() first argument is not (const tchar*), but rather (const wchar_t*), or (const odchar*)
perhaps your code should look like that, to support both configuraitons
cstring s;
m_ctrlttffont.getwindowtext(s);
// no need to convert
lstrcpy(m_charformat.szfacename, (lpctstr)s));
// no ned to convert either
odstring szname((lpctstr)m_charformat.szfacename)
vladimir
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)