I've tried Googling this, and there are so many answers based on various specific situations that frankly I'm more stuck than I was when I started.
The facts are these:
Please help me, either to fix the current attempt at CreateDirectory or to use something else to create a directory.
Thank you!
This is completely crazy. Microsoft have mechanisms to support both ANSI (as they call it) and UNICODE from the same code, because Windows 95/8/Me were ANSI operating systems and NT/XP/Vista etc are UNICODE operating systems. So if you really want to you can write one set of code that supports both systems and just recompile for each system.
But who is interested in Windows 95/98/Me any more? Yet this stuff carries on confusing newbies.
Here's the beef, there is no function called CreateDirectory in Windows, there a UNICODE function called CreateDirectoryW and an ANSI function called CreateDirectoryA. The macro CreateDirectory is converted to CreateDirectoryW or CreateDirectoryA depending on which compiler options you have defined. If you end up using CreateDirectoryW (as you evidentally did) the you must pass a Unicode string to it, if you use CreateDirectoryA then you pass a normal ASCII string.
The simplest thing in your case would be to forget about all this and just call CreateDirectoryA directly.
CreateDirectoryA("c:\\some\\directory", NULL);
Why it is so hard to create a directory in C++? I would guess that because back in the 70s when C was new, not every operating system had directories so this stuff never made it into the language standard.
VS2005 is Unicode by default, and you should better keep it that way. Might save you a lot of issues in the future. In Unicode builds CreateDirectory
(and other Win32 functions) expect wchar_t
strings, and not regular char
. Making string literals wchar_t
's is simple -
L"Some string"
to make it always Unicode, or _T("Some string")
to make it configuration dependent.
I don't know how exactly are you calling CreateDirectory
, but if converting the string to Unicode is too much trouble, you can use the ANSI version directly - CreateDirectoryA
. Post some code if you want a more detailed answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With