Re: Retrieving text from CEdit box as char *?
From: Darren Beckley (darrenbeckley_at_nospamhotmail.com)
Date: 05/22/04
- Next message: inam: "EVC Linker Error [LNK1104: cannot open file 'msvcirt.lib']"
- Previous message: erik: "Re: Retrieving text from CEdit box as char *?"
- In reply to: Mike Hughes: "Retrieving text from CEdit box as char *?"
- Next in thread: r_z_aret_at_pen_fact.com: "Re: Retrieving text from CEdit box as char *?"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 22 May 2004 10:45:43 +0100
Windows CE uses Unicode so strings coming from the OS such as window text
are stored using "wide" characters (2 bytes instead of 1).
If you really need a string of char, you need to convert the CString to
ASCII/ANSI using functions such as WideCharToMultiByte() or wcstombs(). You
may also like to look at MFC Tech Note TN059 which describes some useful
macros such as T2A() that can simplify your code if you do a lot of
conversions.
Alternatively, if you don't actually need the string in ASCII format, just
change char* text_input to LPCTSTR text_input. This gives you a const TCHAR
pointer to the CString buffer.
TCHAR is a generic character type that is either WCHAR or char depending on
whether you build for Unicode or not (look at the pre-processor flags in
your project, you will see something like UNICODE or _UNICODE defined in
eVC++ projects). Most C library functions have a generic function equivelent
that is controlled by this flag. e.g. _tprintf() becomes either wprintf() or
printf().
Hope that helps,
Darren
"Mike Hughes" <anonymous@discussions.microsoft.com> wrote in message
news:7401D145-3045-4F61-8CD0-85270ECA97FF@microsoft.com...
> Hi,
>
> I'm having some trouble with data conversions. I have a edit box that the
user enters information into and then I retrieve the data with either the
GetWindowText() or GetLine() functions. This leaves me with a CString that
I can't seem to do anything with.
>
> I tried the follow code to convert the CString to a char * but it ends up
with the char * only having the first element from the CString in it.
>
> char *text_input;
> CString temp_string;
>
> EditBox->GetWindowText(temp_string);
> text_input = (char *) temp_string.GetBuffer(sizeof(temp_string));
>
> .....
>
> temp_string.ReleaseBuffer();
>
> I also tried to do a straight strcpy of the temp_string into the
text_input (with space allocated for the text_input) but it causes a
compiler error (error C2664: 'strcpy' : cannot convert parameter 2 from
'class CString' to 'const char *').
>
> I'm using eVc++ 4.0 targetted at an ARMV4 device.
>
> Thanks,
>
- Next message: inam: "EVC Linker Error [LNK1104: cannot open file 'msvcirt.lib']"
- Previous message: erik: "Re: Retrieving text from CEdit box as char *?"
- In reply to: Mike Hughes: "Retrieving text from CEdit box as char *?"
- Next in thread: r_z_aret_at_pen_fact.com: "Re: Retrieving text from CEdit box as char *?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|