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?
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:
You can learn more about Microsoft's introduction of Unicode here as well as here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With