This site is no longer active and is available for archival purposes only. Registration and login is disabled.

why is everything widechar?


why is everything widechar?

Postby kornalius » Feb 11, 2004 @ 4:44pm

User avatar
kornalius
pm Member
 
Posts: 1704
Joined: Dec 9, 2003 @ 6:04pm
Location: Montreal, Québec, Canada


Postby refractor » Feb 11, 2004 @ 5:07pm

User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby Dan East » Feb 11, 2004 @ 9:46pm

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby kornalius » Feb 12, 2004 @ 1:05pm

User avatar
kornalius
pm Member
 
Posts: 1704
Joined: Dec 9, 2003 @ 6:04pm
Location: Montreal, Québec, Canada


Postby hm » Feb 12, 2004 @ 5:01pm

User avatar
hm
pm Member
 
Posts: 201
Joined: Dec 28, 2003 @ 8:47pm
Location: Seattle, WA


Postby Dan East » Feb 12, 2004 @ 6:33pm

Well, the real goal is to code in neither UNICODE nor ANSI, but use universal types and methodology so you can build for either. That is what TCHAR and associated types and functions are for.

Along that line, I really don't think L"something" should be used at all. First of all, the syntax is completely counterintuitive to C/C++. Second, it is forcing wide char, so it will not build for ANSI. _T() or _TEXT() are the proper macros to use.

Another technique to that end, that I've demonstrated in examples many times here at PM, is to make certain you correctly note whether the API accepts string lengths by character count or by byte count. Most APIs take the length of the string in characters. So for example:

TCHAR buffer[128];
SomeAPI(buffer, sizeof(buffer)/sizeof(TCHAR));

That will provide the number of characters buffer can hold as the second parameter, while not hardcoding the value within the API call, and will build for both ANSI and UNICODE.

Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum