'Windows directory that will never contain non-ASCII characters for temp file?

Using MinGW 7.3.0 on Windows, Hunspell can't load the dictionary files from locations that have non-ASCII characters because of Windows limitations. I've tried everything[1] and I'm now resorting to copying the file to a path without ASCII characters before giving it to Hunspell. What is a good location to copy it to?

[1]

  1. Windows requires wchar_t support for std::iostream.open() to work right, which MinGW does not implement
  2. std::filesystem can solve this, but only available in GCC 8
  3. Hunspell insists on loading files on its own, it is not possible to pass the read files as strings to it


Solution 1:[1]

From this bug tracker:

In WIN32 environment, use UTF-8 encoded paths started with the long path prefix \\?\ to handle system-independent character encoding and very long path names (without the long path prefix Hunspell will use fopen() with system-dependent character encoding instead of _wfopen()).

So the actual solution seems to be:

  1. Call GetFullPathNameW to normalize the path. Required because paths with long path prefix \\?\ are passed to the NT API unchanged.
  2. Prepend L"\\\\?\\" to the normalized path (backslashes doubled because of C string literal requirements).
  3. For a UNC path, you have to use the "UNC" device directly (i. e. L"\\\\server\\share" ? L"\\\\?\\UNC\\server\\share" (thanks eryksun)
  4. Encode the path in UTF-8, e. g. using WideCharToMultiByte() with CP_UTF8.
  5. Pass the final UTF-8 encoded path to Hunspell.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1