PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

why is everything widechar?

Hi,

Can someone explain to me why eVc most always use widechar strings instead of regular char string for most of the API calls? Can I set something to use normal char string parameters?

Regards,
Kornalius
One word: Unicode.

Calling MessageBox with an ASCII (8-bit) string works fine for European-biased languages, but doesn't work so well for Chinese, etc. Microsoft figured that rather than going to the effort (and space) of supporting both ASCII and Wide function calls, they'd just go with the super-set.

http://msdn.microsoft.com/library/defau ... pc_ode.asp
Remember that Windows CE is meant to be a lightweight subset of Win32, so they tried to reduce as many redundant APIs as possible.

The original Windows CE devices had very small ROMs. My HP Jornada 320LX (Windows CE 1.0, circa 1997) had only a 4 MB ROM (IIRC), so there just wasn't room for the bloat.

Finally, Windows CE offered Microsoft a completely fresh start with an OS. It made sense to make the OS support only UNICODE so the device and applications would be more compatible with foreign languages.

Speaking of old Windows CE devices, I remember upgrading the 320LX from Windows CE 1.0 to 2.0. They sent me a small board with the new ROM on it, which I swapped with the original 1.0 ROM. I also remember when the 360LX came out. That was a big improvement. It had 8 MB of RAM, and had 16 level grayscale instead of the 4 level grayscale the 320LX had. Still have both devices, and they both still work. :)

Dan East
Ok I see. Too bad everything has to be converted before all API calls but hey Microsoft are the ones who decides, not me! :lol:

Regards,
Kornalius

BTW: With all of you help here guys, I can say that my compiler is doing great and is quite impressive for a first PPC project. I will release it eventually.
kornalius wrote:Ok I see. Too bad everything has to be converted before all API calls but hey Microsoft are the ones who decides, not me!

You don't convert. Just use Unicode throughout the app. C/C++ support Unicode strings and Unicode constants right away; say L"blah" instead of "blah". Also, most of the string functions etc. actually have 16-bit equivalents in the standard library. MS has also some macros that yield 16-bit or 8-bit constants depending on some compiler defines. The problem is really more the way C/C++ are still taught, given that nowadays especially all consumer platforms [like Win32, Java, OS X etc.] are native Unicode.

- HM
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