Reputation: 521
I inherited a c++ visual studio project that I can't get to build. The problem is that a lot of api calls like "CreateEvent" have char* inputs being fed to them but the error code expects "LPCWSTR." It's literally hundreds of lines of code with more or less a similar complaint.
Searching for help, the common solution seems to be that I should disable using the Unicode Character Set. However, when I do this, I get the "Building an MFC project for a non-Unicode character set is deprecated" error. Searching for help, the common solution seems to be that I should enable the Unicode Character Set.
So I'm hosed if I do, hosed if I don't. What's the right move here?
Upvotes: 2
Views: 1252
Reputation: 50775
It seems you are using Microsoft Visual Studio 2013. This version was distributed without the MBCS version of MFC. On the other hand Visual Studio 2015 and 2017 come with the MBCS version of MFC.
If you want to build your project with MBCS, you need to download and install this:
https://www.microsoft.com/en-us/download/details.aspx?id=40770
The other option is converting your whole project to Unicode, but this can be a lot of work depending on your project.
Upvotes: 0
Reputation: 2036
CreateEvent
itself is nothing but a macro #define
'd to be one of the two functions which are actually declared in WinAPI's synchapi.h
#ifdef UNICODE
#define CreateEvent CreateEventW
#else
#define CreateEvent CreateEventA
#endif // !UNICODE
Normally (at least in all Windows projects I used to work with) this UNICODE macro is defined, so in fact one works with CreateEventW
function, which accepts LPCWSTR
(in other words const wchar_t*
), words argument, which is supposed to be a UTF-16 string literal.
If it is not defined in your project, then it uses CreateEventA
, which accepts LPCSTR
argument (in fact, equivalent to const char*
), and treats it as ASCII string.
Your project seems to have been set up to support ASCII strings only. And...well, now this is deprecated :) Previously there was some special add-on to enable builds for such situations, called MFC MBCS DLL Add-on. However, I'm not 100% sure it's still available, here's a question here at StackOverflow about that.
If you don't find such addon or any alternative solution like that, then I'm afraid the only way to make it compile will be porting your project to Unicode strings. Actually, even if you find a workaround, I suggest you to add this activity to your backlog if you're going to maintain this project any further, because such workaround may cease to exist at any moment.
In any case, it would be interesting to learn about your end result.
Upvotes: 3