windowsfunctionwinapiunicodeansi

WinAPI Unicode and ANSI functions


Most WinAPI calls have Unicode and ANSI function call

For example:

function MessageBoxA(hWnd: HWND; lpText, lpCaption: LPCSTR; uType: UINT): Integer; stdcall;external user32;

function MessageBoxW(hWnd: HWND; lpText, lpCaption: LPCWSTR; uType: UINT): Integer; stdcall; external user32;

When should I use the ANSI function rather than calling the Unicode function?


Solution

  • The simplest rule to follow is this: Only use the ANSI variants on systems that do not have the Unicode variant. That is on Windows 95, 98 and ME, which are the versions of Windows that do not support Unicode.

    These days, it is exceptionally unlikely that you will be targeting such versions, and so in all probability you should always just use the Unicode variants.