Re: converting 'const wchar_t *' to 'const char * ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



All const char * declarations should be replaced by LPCTSTR. All char * declarations
should be replaced by LPTSTR. Unless there is a compelling reason, std::string and
variations on that theme should not be used; CString is a good bit friendlier to MFC
programs.
joe

On Wed, 5 Dec 2007 20:38:48 -0800 (PST), jklioe <ranu2006@xxxxxxxxx> wrote:

Thanks for ur reply well I was converting a library source code from
ANSCI to UNICODE

in a Function , const char * is used as follow (well I have cut short
the constructor code



InjectMachine(const char * Name,const char * Type)

and this method is called as follow


std::basic_string<TCHAR> Name_;
std::basic_string<TCHAR> Type_;


InjectMachine(Name_.c_str(),Type_.c_str()) // I get an error here when
i complile with UNICODE








On Dec 6, 8:54 am, Joseph M. Newcomer <newco...@xxxxxxxxxxxx> wrote:
First, show some code. The problem is that you are trying to convert a Unicode string to
an 8-bit character string, and we would need to see some context about why you are doing
this. The most common problems are simply coding errors, where you have erroneously
written a program under the delusion that char * is the way to represent a string pointer,
but there are many other issues, and in the absence of a concrete example it is hard to
say what should be done.
joe

On Wed, 5 Dec 2007 19:42:52 -0800 (PST), jklioe <ranu2...@xxxxxxxxx> wrote:
How to convert 'const wchar_t *' to 'const char *' ?

Joseph M. Newcomer [MVP]
email: newco...@xxxxxxxxxxxx
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • RAM usage with arm-gcc
    ... char pointers are taking up a very strange amount of space. ... and the const CHAR etc declarations ... If I move one of the declarations to another file in the project, ...
    (comp.arch.embedded)
  • Re: ora-600 with table...cast... on 10.2.0.3 / al32utf8 / linux
    ... so it may seem logical that declarations of VARCHAR2s ... with CHAR size semantics that may exceed 32Kb limit shouldn't be ... variable-length code point encodings, like UTF-8? ... actually allocating memory Oracle seems to be preparing for the worst ...
    (comp.databases.oracle.server)
  • Re: ora-600 with table...cast... on 10.2.0.3 / al32utf8 / linux
    ... so it may seem logical that declarations of VARCHAR2s ... with CHAR size semantics that may exceed 32Kb limit shouldn't be ... variable-length code point encodings, like UTF-8? ...
    (comp.databases.oracle.server)
  • Re: More structs
    ... int { ... Your phrase "similar ``non-struct'' declarations" I find ... void foo; ...
    (comp.lang.c)
  • Re: K&R-Style Function Declarations: Good or Bad?
    ... >> short parameters getting promoted to int. ... all pre-ANSI compilers widened char and short ... >declarations using the widened types (much as array declarations are ... K&R1 Appendix A explicitly mentions float ...
    (comp.lang.c)