0x90
0x90

Reputation: 41022

how to defualtly define all the winapi to treat strings as UNICODE?

Using visual studio, is there a way to define all the function of the winapi to treat all the strings as UNICODE?

Upvotes: 1

Views: 310

Answers (4)

David Heffernan
David Heffernan

Reputation: 613592

You have to use the L prefix for all your Unicode strings. A non-prefixed string, e.g. "hello", is always a char based string. There is no shortcut in the language that would treat such a string as a wide character string.

Upvotes: 1

Totonga
Totonga

Reputation: 4366

The MS libraries are organized by macros.

  • Use the name of the API methods without the appende "A" or "W".
  • Wrap your string definitions in _T() macro.

By doing this way defining "_UNICODE" in Preprocessor will build unicode build.

CreateFile(_T("C:\out.txt"),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

will resove to:

// _UNICODE defined
CreateFileW(L"C:\out.txt",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

or

// _UNICODE not defined
CreateFileA("C:\out.txt",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

Upvotes: 2

Assaf Levy
Assaf Levy

Reputation: 1312

I think you're looking for this: Project->MyProject Properties->Configuration Properties. Set Character Set to Use Unicode Character Set. That essentially makes your project a unicode one, and all functions now expect unidoe.

Make sure that you carefully review your source after such a wide change.

Upvotes: 1

AndersK
AndersK

Reputation: 36092

When you set your project to compile for Unicode all WinAPI functions will take Unicode strings (if there are unicode function equivalents). However when you specify a string literal in C++ it is by default char* so in order to create Unicode string literals you need to either specify them with the prefix L or use the macro _T( "mystring" ) (Visual Studio)

Upvotes: 1

Related Questions