An easier approach (than using raw Win32 API MultiByteToWideChar) would be to use ATL conversion helpers, like CA2CW. You can specify CP_UTF8 as code page (second parameter in the constructor), to convert from Unicode UTF-8 to Unicode UTF-16:
CreateDirectoryW(
CA2W( utf8Name, CP_UTF8 ) // convert from UTF-8 to UTF-16
... // other stuff
);
Note that in Unicode builds (which should be the default ones these days), CreateDirectory just expands to CreateDirectoryW, so I would just drop the ending "W" and use the (IMHO, more readable) CreateDirectory:
CreateDirectory(
CA2W( utf8Name, CP_UTF8 ) // convert from UTF-8 to UTF-16
... // other stuff
);
W
suffix), not the ANSI versions. Those have been obsolete for decades. – Stenographchar
-based strings rather thanwchar_t
-based strings. If Windows fully supported UTF-8, then you could just use UTF-8 throughout your program instead of having to convert between UTF-8 and UTF-16 all the time. – Adne