The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: vraifreud on October 03, 2007, 08:38:32 AM

Title: Problem in displaying WCHAR
Post by: vraifreud on October 03, 2007, 08:38:32 AM
Hello!
Here's part of my program displaying a WCHAR string:

...
szStr word 0030h,0031h,0032h,0033h,0000h
...
invoke TextOut, hdc, x, y, addr szStr, 4
...

The String Displayed is "0??" where "?" is a char that I cannot type, while I expect it to be "0123". What is the problem? Thanks.
Title: Re: Problem in displaying WCHAR
Post by: Tedd on October 03, 2007, 12:06:12 PM
"TextOut" is actually a shortcut to "TextOutA" which will assume the text you give it is ansi - use "TextOutW" explicitly.
(The same goes for most other function that have string parameters.)
Title: Re: Problem in displaying WCHAR
Post by: u on October 03, 2007, 06:16:39 PM
To identify which API have both an ANSI and Widechar versions, simply look-out for paremeters of type:
LPCTSTR and LPTSTR . (Long Pointer to [Constant] Template STRing). The "Template" part means that there are 2 versions of the function. Internally in Win2k and later, for these API, ANSI strings get converted to Widechar.

LPTSTR is either a LPSTR (ANSI) or LPWSTR (Widechar).
LPCTSTR is either a LPCSTR or LPCWSTR

In C/C++ projects, at compile-time the windows.h header-files specify for each of those duplicated functions:
#ifdef _UNICODE
   #define TextOut  TextOutW
#else
   #define TextOut  TextOutA
#endif

You manually define _UNICODE in your .c/.h files, or set the project-options for compilation to pass a pre-define of _UNICODE on the command-line of the compiler.