Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between these Windows API signatures in Delphi?

Looking Windows.pas in Delphi, I see that there are several signatures as LoadLibrary (A) or (W) for loading a specific module. What are the differences between them and could I trust to call LoadLibrary always for all types of Windows platforms?

like image 820
Caitano Oliveira Avatar asked Jun 08 '15 00:06

Caitano Oliveira


1 Answers

The Windows API provides either ANSI strings (A) or Unicode strings (W). Interally, the Windows API has both available. However, Delphi is defaulted to either one or the other, depending on the version of Delphi. Many other Windows languages do this too. The language uses either ANSI or Unicode strings as a default.

In Delphi versions prior to 2009, the ANSI API calls were used, suffixed with an A. That was when Delphi primarily used ANSI strings. As of Delphi 2009 and above, Unicode has been enforced. That also made the default API calls to Unicode, suffixed with a W. Unicode has always been supported in Delphi, but as of 2009 it's been enforced as the default, favored over ANSI. In those older versions, functions such as LoadLibrary mapped to the ANSI version LoadLibraryA.

The particular API call you're referring to LoadLibrary is available as either LoadLibraryA or LoadLibraryW. Windows.h also provides a generic LoadLibrary function, which internally uses the preferred Unicode version. The A and W difference provides developers the option for backwards compatibility, as with many of Microsoft's products. If the language is primarily ANSI Strings, you can explicitly use Unicode. Or, if the language is primarily Unicode, you can explicitly use ANSI.

Long story short, at one point Windows itself made the switch from ANSI strings to Unicode strings as default. However still provided backwards compatibility. Later Delphi versions have been changed to use whatever the preferred defaults are - in this case they're Unicode.

To summarize:

  • LoadLibraryA - Loads library via ANSI strings
  • LoadLibraryW - Loads library via Unicode strings
  • LoadLibrary - Loads library using preferred default (Unicode Strings)
  • Ancient versions of Windows used only ANSI strings before introducing Unicode
  • Windows provided backwards compatibility by defaulting to ANSI versions - but eventually switched defaults to Unicode (not sure at which version)

You can learn more about Microsoft's introduction of Unicode here as well as here.

like image 193
Jerry Dodge Avatar answered Oct 01 '22 06:10

Jerry Dodge