mastodon.gamedev.place is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mastodon server focused on game development and related topics.

Server stats:

5.4K
active users

Ashley Gullen

If you thought JavaScript was a mess, here's what it takes to pass a file path to a Windows API in C++: 🧵
- Windows uses UTF-16, but most modern software uses UTF-8
- Converting UTF-8 to UTF-16 requires calling MultiByteToWideChar twice (once for size, second to convert)
- Alternatively you can set the process code page to UTF-8 and call the 'A' variant API directly, but only sometimes, and only with Windows 10 v1903+, and you might still have to change the system locale setting and reboot
(1/3)

- Now you can pass a file path! But...
- The path is limited to MAX_PATH (260 chars)
- Unless you prefix the path with \\?\
- However using \\?\ disables automatic conversion of / to \ in the path (and some other normalization)
- Alternatively set a reg key LongPathsEnabled, but only with Windows 10 v1607+ and the app needs to opt in to longPathAware, and changing the registry might need a reboot
(2/3)

- Even then not all Windows APIs support longer paths, e.g. PathCanonicalize. Swap for PathCchCanonicalizeEx with PATHCCH_ALLOW_LONG_PATHS, etc. Check docs per API.
- Congratulations, your app can pass a long file path to Windows! But the shell still doesn't support long paths. So your app can write to long paths, but you can't access them with Windows Explorer. Even in Windows 11.
- If the API returns a path, do all that in reverse.
(3/3)

We build Construct, browser-based game creation software, and we've been working on C++ integration lately. We sometimes blog on other interesting tech stuff we're working on. See our site for more! construct.net

www.construct.netGame Making Software - Construct 3 ★★★★★Construct 3 is the worlds best game making software. Make your own game in your browser without coding or with Javascript. Building games has never been easier!

@AshleyGullen I ran into the issue of converting between UTF-8 and UTF-16 when I was using Lua as the primary language for a desktop application in 2008. I ended up patching the Lua standard library's io and os modules, as well as the lfs library.

These days I do a lot of work with Rust. The Rust standard library takes care of conversion between UTF-16 and UTF-8. But I wonder how thoroughly it handles the problem of long paths.

@matt @AshleyGullen
Rust is uhh... special wrt paths. It'll pass whatever you input to let the OS deal with it and return whatever it gets back. It's specifically `std::fs::canonicalize` that nets the weird extended form paths that allow long path names