几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   DirectDWG (http://www.dimcax.com/hust/forumdisplay.php?f=89)
-   -   【转帖】how can i convert odstring to cstring (http://www.dimcax.com/hust/showthread.php?t=16538)

yang686526 2009-05-05 12:14 PM

【转帖】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


所有的时间均为北京时间。 现在的时间是 12:43 PM.