  | | | C++ question | C++ question 2004-06-10 - By Alain Laferrière
Back Thanks Jerry.
__ __
From: owner-xsi@(protected) [mailto:owner-xsi@(protected)] On Behalf Of Jerry Gamache Sent: Friday, June 11, 2004 3:40 AM To: XSI@(protected) Subject: RE: C++ question This seems like too much code. This can probably be simplified to: // string buffers char charString[1024]; // convert CString to char wcstombs( charString, myCString.GetWideString(), 1024 ); And prevents a potential buffer overflow crash in swprintf if the string happens to be longer than 1024 characters. If you really want the intermediate buffer, at least use _snwprintf instead of swprintf. http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/buffer-overflow .html
-- --Original Message-- -- From: owner-xsi@(protected) [mailto:owner-xsi@(protected)]On Behalf Of Alain Laferrière Posted At: Thursday, June 10, 2004 12:31 PM Posted To: xsi Conversation: C++ question Subject: RE: C++ question Example ( myCString is the CString which gets converted to char string ) : // string buffers char charString[1024]; wchar_t wcharString[1024]; // convert CString to char swprintf( wcharString, L"%s", myCString.GetWideString() ); wcstombs( charString, wcharString, 1024 );
__ __
From: owner-xsi@(protected) [mailto:owner-xsi@(protected)] On Behalf Of François Painchaud Sent: Thursday, June 10, 2004 11:53 PM To: XSI List Subject: Re: C++ question CString stores wide characters. Use CString method "const wchar_t* GetWideString() const", then use "FILE* _wfopen( const wchar_t* filename, const wchar_t* mode )" or a similar open function. You could also take a look at function "int wctomb( char* mbchar, wchar_t wchar )". François -- ----- Message d'origine -- ----- Sujet: C++ question Date: Thu, 10 Jun 2004 15:58:11 +0200 De: "Helge Mathee" <helge.mathee@(protected)> <mailto:helge.mathee@(protected)> A: <XSI@(protected)> <mailto:XSI@(protected)>
Maybe I am dumb..... how to convert a CString to a const char *? I need this to read files inside of a c++ operator... really weird... just doesn't work... thanks, helge
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE></TITLE> <META http-equiv=Content-Type content="text/html; charset=iso-8859 (See http://iso-8859.ora-code.com)-1"> <META content="MSHTML 6.00.2737.800" name=GENERATOR></HEAD> <BODY bgColor=#ffffff> <DIV dir=ltr align=left><FONT face=Arial color=#000080 size=2></FONT> </DIV> <DIV dir=ltr align=left><SPAN class=413501919-10062004><FONT face=Arial color=#000080 size=2>Thanks Jerry.</FONT></SPAN></DIV><BR> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left> <HR tabIndex=-1> <FONT face=Tahoma size=2><B>From:</B> owner-xsi@(protected) [mailto:owner-xsi@(protected)] <B>On Behalf Of </B>Jerry Gamache<BR><B>Sent:</B> Friday, June 11, 2004 3:40 AM<BR><B>To:</B> XSI@(protected)<BR><B>Subject:</B> RE: C++ question<BR></FONT><BR></DIV> <DIV></DIV> <DIV><SPAN class=093351318-10062004><FONT face="Comic Sans MS" color=#008080 size=2>This seems like too much code. This can probably be simplified to:</FONT></SPAN></DIV> <DIV><SPAN class=093351318-10062004><FONT face="Comic Sans MS" color=#008080 size=2></FONT></SPAN> </DIV> <DIV><SPAN class=093351318-10062004><FONT face="Comic Sans MS" color=#008080 size=2> <DIV dir=ltr align=left><FONT face=Arial color=#000080 size=2> // string buffers <BR> char <SPAN class=157212616-10062004> charString</SPAN>[1024 ];<BR></FONT></DIV> <DIV><FONT face=Arial color=#000080 size=2></FONT> </DIV> <DIV dir=ltr align=left><FONT face=Arial color=#000080 size=2> // convert CS<SPAN class=157212616-10062004>t</SPAN>ring to char<BR> wcstombs( charString, <SPAN class=157212616-10062004>my</SPAN><SPAN class=157212616-10062004>CString</SPAN>.GetWideString(), 1024 );<BR></FONT></DIV></FONT></SPAN></DIV> <DIV><SPAN class=093351318-10062004><FONT face="Comic Sans MS" color=#008080 size=2>And prevents a potential buffer overflow crash in swprintf if the string happens to be longer than 1024 characters.</FONT></SPAN></DIV> <DIV><SPAN class=093351318-10062004><FONT face="Comic Sans MS" color=#008080 size=2></FONT></SPAN> </DIV> <DIV><SPAN class=093351318-10062004><FONT face="Comic Sans MS" color=#008080 size=2>If you really want the intermediate buffer, at least use _snwprintf instead of swprintf.</FONT></SPAN></DIV> <DIV><SPAN class=093351318-10062004><FONT face="Comic Sans MS" color=#008080 size=2><A href="http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/buffer -overflow.html">http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO /buffer-overflow.html</A></FONT></SPAN></DIV> <DIV><SPAN class=093351318-10062004><FONT face="Comic Sans MS" color=#008080 size=2></FONT></SPAN> </DIV> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma size=2>-- --Original Message-- --<BR><B>From:</B> owner-xsi@(protected) [mailto:owner-xsi@(protected)]<B>On Behalf Of </B>Alain Laferrière<BR><B>Posted At:</B> Thursday, June 10, 2004 12:31 PM<BR><B>Posted To:</B> xsi<BR><B>Conversation:</B> C++ question<BR><B>Subject:</B> RE: C++ question<BR><BR></FONT></DIV> <DIV dir=ltr align=left><FONT face=Arial color=#000080 size=2></FONT> </DIV> <DIV dir=ltr align=left><FONT face=Arial color=#000080 size=2><SPAN class=157212616-10062004>Example ( <SPAN class=157212616-10062004>my</SPAN><SPAN class=157212616-10062004>CString is the CString which gets converted to char string ) :</SPAN></SPAN></FONT></DIV> <DIV dir=ltr align=left><FONT face=Arial color=#000080 size=2><SPAN class=157212616-10062004></SPAN></FONT><FONT face=Arial color=#000080 size=2><SPAN class=157212616-10062004></SPAN></FONT><FONT face=Arial color=#000080 size=2><SPAN class=157212616-10062004></SPAN></FONT><FONT face=Arial color=#000080 size=2></FONT> </DIV> <DIV dir=ltr align=left><FONT face=Arial color=#000080 size=2> // string buffers <BR> char <SPAN class=157212616-10062004> charString</SPAN> [1024];<BR><SPAN class=157212616-10062004> </SPAN>wchar_t <SPAN class=157212616-10062004> wcharString</SPAN>[1024];</FONT></DIV> <DIV><FONT face=Arial color=#000080 size=2></FONT> </DIV> <DIV dir=ltr align=left><FONT face=Arial color=#000080 size=2> // convert CS<SPAN class=157212616-10062004>t</SPAN>ring to char<BR> swprintf( <SPAN class=157212616-10062004>wcharString</SPAN>, L"%s", <SPAN class=157212616-10062004>my</SPAN><SPAN class=157212616-10062004>CString</SPAN>.GetWideString() );<BR> wcstombs( charString, wcharString, 1024 );<BR></FONT></DIV><BR> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left> <HR tabIndex=-1> <FONT face=Tahoma size=2><B>From:</B> owner-xsi@(protected) [mailto:owner-xsi@(protected)] <B>On Behalf Of </B>François Painchaud<BR><B>Sent:</B> Thursday, June 10, 2004 11:53 PM<BR><B>To:</B> XSI List<BR><B>Subject:</B> Re: C++ question<BR></FONT><BR></DIV> <DIV></DIV>CString stores wide characters. Use CString method "const wchar_t* GetWideString() const", then use "FILE* _wfopen( const wchar_t* filename, const wchar_t* mode )" or a similar open function. You could also take a look at function "int wctomb( char* mbchar, wchar_t wchar )".<BR><BR>François<BR> <BR>-- ----- Message d'origine -- ----- <TABLE cellSpacing=0 cellPadding=0 border=0> <TBODY> <TR> <TH vAlign=baseline noWrap align=right>Sujet: </TH> <TD>C++ question</TD></TR> <TR> <TH vAlign=baseline noWrap align=right>Date: </TH> <TD>Thu, 10 Jun 2004 15:58:11 +0200</TD></TR> <TR> <TH vAlign=baseline noWrap align=right>De: </TH> <TD>"Helge Mathee" <A class=moz-txt-link-rfc2396E href="mailto:helge.mathee@(protected)"><helge.mathee@(protected)></A> </TD></TR> <TR> <TH vAlign=baseline noWrap align=right>A: </TH> <TD><A class=moz-txt-link-rfc2396E href="mailto:XSI@(protected)"><XSI@(protected)></A></TD>< /TR></TBODY></TABLE><BR> <META content="MSHTML 6.00.2737.800" name=GENERATOR> <STYLE></STYLE>
<DIV><FONT face=Arial size=2>Maybe I am dumb.....</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>how to convert a CString to a const char *?</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>I need this to read files inside of a c++ operator...</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>really weird... just doesn't work...</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>thanks,</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>helge</FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
|
|
 |