Author Topic: wide charatcers  (Read 6650 times)

Offline jmccay

  • Almost regular
  • **
  • Posts: 202
wide charatcers
« on: October 03, 2006, 04:31:30 am »
Does anyone know of any good tutorials on using wide characters (& Unicode) with mingw (& in C++ general)?

jmccay
OS: WinXP, Win98 SE, & sometimes Linux

a little light reading from the wxWidgets 2.6.2 readme: A detailed 2000-page reference manual is supplied in HTML, PDF and Windows Help form: see the docs hierarchy.

Offline David Perfors

  • Developer
  • Lives here!
  • *****
  • Posts: 560
Re: wide charatcers
« Reply #1 on: October 03, 2006, 09:29:16 am »
I don't know a good tutorial, but in C++ you can use wchar_t for characters and std::wstring for strings... I think that is the official way for using wide characters in C++
OS: winXP
Compiler: mingw
IDE: Code::Blocks SVN WX: 2.8.4 Wish list: faster code completion, easier debugging, refactoring

Offline jmccay

  • Almost regular
  • **
  • Posts: 202
Re: wide charatcers
« Reply #2 on: October 04, 2006, 02:50:42 am »
What about all the char functions?  Like the wide char equivilant of sprintf (swprintf)?  That's what I was reallylooking for info about.

jmccay
OS: WinXP, Win98 SE, & sometimes Linux

a little light reading from the wxWidgets 2.6.2 readme: A detailed 2000-page reference manual is supplied in HTML, PDF and Windows Help form: see the docs hierarchy.

Online stahta01

  • Lives here!
  • ****
  • Posts: 6769
    • My Best Post
Re: wide charatcers
« Reply #3 on: October 04, 2006, 03:49:38 am »
Did you look in wchar.h and see if the function exists? Did you include it?

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: wide charatcers
« Reply #4 on: October 04, 2006, 09:00:46 am »
Challenging Google with "standard library wide character functions" leads to about as many helpful sites as searching for "Amendment 1 to ISO C90". Several of them, for example the Debian one, have code examples.

The GNU C Libarary's documentation and MSDN (Visual C++ section) have chapters on it, too.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline krisz

  • Single posting newcomer
  • *
  • Posts: 4
Re: wide charatcers
« Reply #5 on: October 04, 2006, 11:40:52 am »
Hi,
I am not really sure about this (excuse me MinGW guys if I am wrong), but I think for MinGW the wide char support is fully ported.  :?:
However I has not tried yet, but I would recommend to link against STLPort library (should contain all the standard wide char support.)  :idea:
Bye, K

Offline severach

  • Multiple posting newcomer
  • *
  • Posts: 44
Re: wide charatcers
« Reply #6 on: October 08, 2006, 06:18:24 pm »
The compiler doesn't matter. Once they allow L before 'c' and "String" they support UNICODE. My favorite tutorial is in Programming Windows by Charles Petzold. Just for fun I Googled "UNICODE _UNICODE Tutorial" and I found a decent tutorial.

http://www.flipcode.com/articles/article_advstrings01.shtml

A few comments

>#define _UNICODE
Generally you place -D_UNICODE on the compile line so it's there for all source files and easy to remove or make multiple compiles.

>#include <tchar.h>   // Include Unicode support functions
These are the macros. The wide functions are defined elsewhere but #include <windows.h> typcially gets most of them.

>wchar_t mystring[] = _TEXT("flipcode");

Bad code! WCHAR is preferred to match existing Windows types. wchar_t is always wide and _TEXT() is wide only when -DUNICODE. Either of the following are acceptable.
WCHAR mystring[] = L"flipcode";
TCHAR mystring[] = _TEXT("flipcode");

My little UNICODE tutorial:

Compiler support:If the compiler accepts L before strings, such as L'C' or L"String", UNICODE is supported.

Library support: Libraries now provide wide versions of most common functions such as snwprintf, wcslen, and wmemcpy. Library standards are trying to push out the old unsafe functions so they are often prefixed with an _ depending on what state of flux your compiler is in. Search those include files.

TCHAR is a system of macros that allow your programs to compile as UNICODE (WCHAR) or Ansi (CHAR) as desired just by adding or removing /DUNICODE and /D_UNICODE to your compile lines. Unless your app is never going to be compiled in Ansi it is best to develop entirely in TCHAR. Each time you forget to use TCHAR, WCHAR, or the _T() macro the compiler will beat you with a stick and after enough beatings you'll get to where you do it right almost every time. You'll want to compile Ansi occasionally to ensure that you haven't inadvertantly used a TCHAR where a CHAR or WCHAR belongs and when debugging code that depends on exact pointer behavior. With a few dirty compiler tricks, well written TCHAR code can be made to simultaneously generate UNICODE and Ansi functions without code duplication.

Plan on using the cb and cch Hungarian prefixes. You will need them.

Many <tchar.h> files are incomplete. If you think there's a WCHAR or TCHAR version of a library function, there probably is. Search the header files and create your own defines when necessary.

#if defined(__MINGW32__) || defined(_MSC_VER) && !defined(__POCC__)
#ifdef _UNICODE
#define _tmemmove wmemmove
#else
#define _tmemmove memmove
#endif
#endif

« Last Edit: October 08, 2006, 06:40:57 pm by severach »

Offline jmccay

  • Almost regular
  • **
  • Posts: 202
Re: wide charatcers
« Reply #7 on: October 10, 2006, 03:03:44 am »
Sorry it has taken me so long to reply, but I was sick last weekend when I was going to get back to this.  I should have been more clear.  I want to do Unicode programming on multiple platforms (windows XP & Linux) using mingw 3.4.5 for the moment, but I realise I would have to support other compilers.  I am also looking for the gotchas from those who have already done it programmed on both environments (or just one).

   My plan is to try and convert UML Pad to Unicode as a test / trial by fire learning experience.  I did some Google-ing and I have put together the following list:


   I have not had a chance to review the stuff mentioned above yet, and I will review them.  It seems I need to download & compile stlport to get wide character stream support.  Is that true?  Thank you for the help.

jmccay
« Last Edit: October 12, 2006, 02:58:21 am by jmccay »
OS: WinXP, Win98 SE, & sometimes Linux

a little light reading from the wxWidgets 2.6.2 readme: A detailed 2000-page reference manual is supplied in HTML, PDF and Windows Help form: see the docs hierarchy.

Offline jmccay

  • Almost regular
  • **
  • Posts: 202
Re: wide charatcers
« Reply #8 on: October 12, 2006, 02:59:50 am »
Is there a linux equivilant to tchar.h?  I could probably use the mingw version since it is public domain.  Has anyone tried this?
jmccay
OS: WinXP, Win98 SE, & sometimes Linux

a little light reading from the wxWidgets 2.6.2 readme: A detailed 2000-page reference manual is supplied in HTML, PDF and Windows Help form: see the docs hierarchy.