0

For example PdhAddEnglishCounterA. I see sometimes the same APIs with different letters. For example: PdhAddCounterW and PdhAddCounterA.

What do these mean? Why are they there?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
TreeWater
  • 761
  • 6
  • 13
  • this api have different signatures - `LPCWSTR` vs `LPCSTR`, for be *c* compatible need use different names. very many windows api have unicode (*W*) and ansi (*A*) versions. ansi version almost always shim over unicode version – RbMm Jan 31 '20 at 23:08
  • Oh wow I didn't even see that. Completely overlooked -_- Thanks! – TreeWater Jan 31 '20 at 23:17
  • In case it isn't clear, you don't want to use the A versions. – David Heffernan Feb 01 '20 at 07:11
  • @DavidHeffernan, it seems the tide is changing on that considering the new *per-process* support in Windows 10 for setting the [activeCodePage](https://learn.microsoft.com/en-us/windows/uwp/design/globalizing/use-utf8-code-page) for the ANSI API to UTF-8. – Eryk Sun Feb 01 '20 at 08:06
  • It would be better, IMO, to support an application setting to use the user locale codepage for the current session, and allow the user to override the legacy codepage to use UTF-8 in the control panel "region" dialog. This would be similar to the beta support in Windows 10 for UTF-8 in the system locale, but much more conservative and easier to work with (no reboot required). It would also unify the CRT `setlocale(LC_CTYPE, "")` use of the user-locale codepage with the ANSI codepage -- finally after almost 30 years of disagreement. – Eryk Sun Feb 01 '20 at 08:08
  • 1
    @ery: UTF-8 (or any other codepage) in the API set formerly known as the ANSI version isn't going to magically fix the limitations inherent to character set conversions. There's always going to have to be a temporary buffer involved. And more likely than not, that buffer is going to be statically sized. If you want to allow a user to open a file *anywhere* in their file system, you better not be calling `CreateFileA`. – IInspectable Feb 01 '20 at 08:38
  • @IInspectable, if a cross-platform application can more conveniently use UTF-8 and only needs to run on Windows 10 systems (in a known organization context -- for now, but eventually in a general context Windows 8 will be EOL), it certainly can rely on setting its ANSI codepage to UTF-8. If the system doesn't have long paths enabled (at an organization level that's a simple problem to solve), then `CreateFileA` will be limited to `MAX_PATH`. In that case, longer paths would require special handling to create "\\?\" non-normalized paths, but *most* applications do not. – Eryk Sun Feb 01 '20 at 14:14
  • @IInspectable, FYI, the documentation claim that `CreateFileA` is always limited to `MAX_PATH` characters (even if long paths are enabled, or even with "\\?\" non-normalized paths) is outdated and has been since Windows 8, which switched the ANSI API to dynamic buffer allocation. It supports transcoding up to NT's maximum allowed 32,767 UTF-16 code points. Windows 7 and earlier used a static buffer for ANSI transcoding, which was limited to `MAX_PATH`, but Windows 7 is now EOL. – Eryk Sun Feb 01 '20 at 14:38

0 Answers0