r/cpp • u/holyblackcat • Sep 05 '26
Escaping `CreateProcess()` arguments on Windows
https://holyblackcat.github.io/blog/2026/09/05/escaping-createprocess-arguments.html
93
Upvotes
r/cpp • u/holyblackcat • Sep 05 '26
View all comments
11
u/fdwr fdwr@github 🔍 Sep 06 '26 edited Sep 06 '26
Note narrow
mainworks fine if your app .manifest file specifies UTF-8 as the default code page (ignoring whatever the system is set). It's annoying to have to include this extra snippet, but then it ensures the other parts of your program work nicely too, such asstd::filesystem::path()returning anstd::stringwith UTF-8 characters (rather than throwing an exception upon seeing untransformable characters, or needing to callu8string()and reinterpret cast it in several places):Another way to get the command line (didn't see mentioned) is using
WinMainas an alternate entry point (rather than main) for CLI apps, as it includes thelpCommandLineparameter directly: