Easy Code
visual projects can
build ANSI or Unicode applications in a very easy way. To
switch between ANSI and Unicode mode, just check/uncheck
the This project will run in Unicode mode (Windows NT
or later) option in the Project Properties. If that option is checked,
the built application
will be Unicode, otherwise it will be ANSI
(default).
In order to maintain compatibilty with all Windows platforms,
32-bit Unicode applications will dynamically switch to ANSI
when running on Windows 95/98/ME. On the other hand,
applications not built as Unicode (that is, having the
This project will run in Unicode mode option
unchecked) will always be ANSI although they run on Windows
NT or later systems. For you to know which mode your
application is running in, call the IsAppUnicode
method, which returns TRUE
or FALSE
depending on
whether the application is running as Unicode or not. That
way, you can prepare an application to work fine in all Windows
versions. To do so, just take care of using the appropiate
functions and messages when they are related to text, and
passing the text strings in the right format.
Easy Code also defines the APP_UNICODE
constant, ONLY if
the application is built as Unicode. This constant is
defined at compile time and it is also available for classic
projects. However, if the project is running on Windows95/98/ME,
it will be running as ANSI even though the APP_UNICODE
is defined.
There are some macros to deal with ANSI/Unicode
text. TextStrA always
returns
an ANSI string, TextStrW always
returns a
Unicode string and TextStr returns an
ANSI or
Unicode string, depending on whether the
This project will run in Unicode mode option is
checked or not. Also, all Easy Code methods
using text strings have their corresponding ANSI
and Unicode versions. For example, the SetText
method is complemented with SetTextA
and SetTextW.
The SetText
method automatically calls the ANSI or Unicode version
depending on which platform of Windows it is running on
and whether the application was built as Unicode or not,
while SetTextA
and SetTextW
always call, respectively, the ANSI and Unicode version
of the method (see Easy
Code methods). That way
you can mix ANSI and Unicode text in the same application.
Let's see some sample code (where hWnd
is the handle to the object which text is to be set):
IFDEF APP_UNICODE
Mov Eax/Rax, TextStrW("Hello") ;Unicode mode
ELSE
Mov Eax/Rax, TextStrA("Hello") ;ANSI mode
ENDIF
Invoke SetText, hWnd, Eax/Rax
Invoke SetTextA, hWnd, TextStrA("Hello")
Invoke IsAppUnicode
.If Eax/Rax
Invoke SetWindowTextW, hWnd, TextStrW("Hello") ;Unicode mode
.Else
Invoke SetWindowTextA, hWnd, TextStrA("Hello") ;ANSI mode
.EndIf
Invoke SetText, hWnd, TextStr("Hello")
For GoAsm projects you may want to use
the DSS
type (Easy Code defined), which makes a text
string to be ANSI, in ANSI projects, or to be a Unicode string in
Unicode projects.
szHello DSS 'Hello', 0
Also,
Easy Code defines the CHARSIZE
constant, which has a value of 1
or 2
depending on whether ANSI or Unicode mode is being used. So, if you
need to increase a string pointer by one character,
you can use the CHARSIZE
constant as follows: