Thread: Should I go to unicode?

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    Should I go to unicode?

    Howdy,

    Reading an article at www.JoelOnSoftware.com about unicode, and the chapter in Petzolds "Programming Windows" book about unicode, I have come to realize how important unicode is.

    Pretty simple question I want to ask, should I move my server program to unicode? Most of the stuff I use can be made into unicode pretty easily, just changing my 'string' to 'wstring' and so on. How important do you think it would be for the server to go to unicode? Will this help it be more multinational? Its NT based so really I should be using unicode by default anyway.

    Also, I use a few things like FILE *'s, is it possible to make them Unicode? I know i can do it with iostreams and stringstreams and most other std stuff, but I'm not so sure about FILE*s. I look forward to hearing everyones thoughts on this

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Also, how can I use winsock functions with unicode? send() and recv() both take char * arguments...

  3. #3
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    send() and recv() are used to send bytes of data. So just do a cast to (char*) if you're using wchar_t.

    Check out this old post. Ken Fitlike summarises how to use Unicode in the Windows API.

    http://cboard.cprogramming.com/showt...define+UNICODE

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    I always use unicode when I am dealing with strings that should go to or come from the user, including pathnames. I know how annoying it is to have unicode in a pathname and watch programs barf when they try to open a file. Unfortunately, this means I can't use the Standard Library (even wofstreams use char * pathnames, not wchar_t * pathnames) so I use the slightly more complicated WinAPI (doesn't have the nice stream operators).

    I often use plain old char* strings for things like logging, etc.
    Last edited by Cat; 10-12-2003 at 12:19 AM.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  5. #5
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    If I get a request sent to the server, and I call the microsoft function IsTextUnicode or whatever its called on the string they give me, and if its in unicode I call send() and cast the information im sending as a char * (it will be in unicode), is that safe? If the request isn't in unicode I'll handle it as ASCII.

  6. #6
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Those crazy foreigners! ASCII for life!

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Originally posted by stovellp
    If I get a request sent to the server, and I call the microsoft function IsTextUnicode or whatever its called on the string they give me, and if its in unicode I call send() and cast the information im sending as a char * (it will be in unicode), is that safe? If the request isn't in unicode I'll handle it as ASCII.
    Well, functions to determine if text is unicode don't always work. Why not start out by sending an ASCII header string, then use that string to tell the server what kind of data follows.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I believe it is a web server, so any type of client could connect.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  9. #9
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Many protocols like SMTP and HTTP only work with ASCII.
    Also note that its not necessary to terminate any string you send with a NULL character, because you are communicating with other servers/clients that may be written in other programming languages.

  10. #10
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Ahh ok, so if I send all the headers in ASCII, and send the files as either ASCII or Unicode (depending on what IsTextUnicode tells me), should that be ok?

  11. #11
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    That should not be a problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <string> to LPCSTR? Also, character encoding: UNICODE vs ?
    By Kurisu33 in forum C++ Programming
    Replies: 7
    Last Post: 10-09-2006, 12:48 AM
  2. Unicode - a lot of confusion...
    By Jumper in forum Windows Programming
    Replies: 11
    Last Post: 07-05-2004, 07:59 AM
  3. UNICODE and windows.h help
    By nextus in forum Windows Programming
    Replies: 3
    Last Post: 03-02-2003, 03:13 PM
  4. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 01:00 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM