I see everyone everywhere declaring both the “A” and “W” versions of an API function.
I did quite a bit of searching, but cannot figure out when exactly the A version is required by the API and the W.
What I’ve read is that the APIs in Windows exclusively use the “W” version, and the “A” version just maps to the “W” version anyway.
I understand the differences between ANSI and Unicode, that’s not the question.
The question is why does everyone declare BOTH types instead of just using the “W” version?
Take a look at the CreateFileA and at the CreateFileW documentation.
The first parameter lpFileName (LPCSTR) is a pointer to an ascii string for CreateFileA but the same parameter for CreateFileW (LPCWSTR) is a pointer to an UTF16 unicode string.
Also the docs reports that the maximum string length is different for the two function version.
So “A” is for encoded ascii string and “W” is for UTF16 unicode strings.
Xojo does automatic conversion between WString (UTF16 unicode) and String (native default UTF8 unicode).
In general you will use only the “W” version of the API
A is ANSI, W is Unicode 16, Words. W doubles the size of parameters in case of you using only 0-255 char sets. When handling some international char sets there’s no option and you’ll need the “Words” version to use extended char sets. English speakers not caring much about internationalization usually just use the legacy ANSI coding with the simpler strings.
Older versions like XP (maybe even Vista?) and below, generally. I still typically consider it unsafe to only implement the wide variant as we’ve seen MS not incorporate those functions in one area while doing so in another before.
Some Xojo users go back and forth between Xojo versions to support older operating systems. It’s the whole reason API 2.0 went down as poorly as it did. There’s no reason to be ignorant of other people’s needs.
[quote=468325:@Christian Schmitz]If I remember correctly most A versions just convert text to unicode and call W function internally.
But not sure where I read that… long ago.[/quote]
On more modern versions of Windows, sure, that may be true.
Long story short, if you want to cover your bases, check for the Wide variant function in your code with System.IsFunctionAvailable. If it exists, execute that. If not, fallback to the A function and you know you’re safe.
Not “ignorant”, such cited fact had not such intention, no need to be aggressive. Yes, sometimes I forget some users still use XP and Realstudio 2011, but I’m not being ignorant when doing so. Try to be a bit more polite please.
Sure, but WHEN would it ever need to fall back? From what I’ve read, it seems like the “A” versions of Windows API functions were deprecated 20 years ago.
Nothing wrong with covering bases, but if you’re still putting in support for RS-232 mice and Parallel printers, (if we actually had to do that because the OS didn’t take care of that), would it really be sensible?
I think it might be easier to just test the version of Windows in your app and then pop up a message when they try to run it on Windows 3.1 that they need to update their life!