MFC library UNICODE not defined while project property "Character Set" is "User Unicode Character Set"

Hadrien FOLLET 21 Reputation points
2022-11-08T11:28:40.117+00:00

I want my project to use UNICODE char. set. I have 4 project in one solution with projects properties "Character Set" set to "User Unicode Character Set". When I execute the code, an exception is raised in one of MFC file (viewprnt.cpp) one line "ENSURE(pInfo->m_strPageDesc.LoadString(AFX_IDS_PREVIEWPAGEDESC));".

When I go to "LoadString(...)" definition, it's a macro chosing between :

  • LoadStringW for Unicode
  • LoadStringA for others # ifdef UNICODE

define LoadString LoadStringW

else

define LoadString LoadStringA

endif // !UNICODE

(libloaderapi.h)

LoadStringW should be used as all of my projects are in unicode but it is actually LoadStringA because it seems like UNICODE is not defined. I'm pretty sure this is why the exception is raised.

How can I force MFC to use UNICODE or where should I define UNICODE to be taken into account by MFC. I tried putting it in "StdAfx.h" without success.

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
{count} votes

Answer accepted by question author
  1. RLWA32 51,366 Reputation points
    2022-11-09T08:57:54.927+00:00

    A typical resource file (.rc) created by the MFC new application template will include the following -

    258609-mfcresource.png

    The inclusion of afxprint.rc provides the resources needed for print preview into your statically linked MFC application. If this is not present, the application will build but will fail at the indicated point because the resources needed for print/print preview are missing.


3 additional answers

Sort by: Most helpful
  1. Hadrien FOLLET 21 Reputation points
    2022-11-09T08:13:46.973+00:00

    258675-assertion-failed.png

    Hello, I misspoke as it is an assertion failure raised by the "ENSURE" call. I'm still trying to find the reason why it returns false by step by steping in MSVC code. As it is a lot of message being dispateched in MESSAGE_MAP, it is pretty tedious. I am indeed using MFC as a static lib. Thanks again for your help.

    0 comments No comments

  2. Hadrien FOLLET 21 Reputation points
    2022-11-09T08:20:25.553+00:00

    It actually throws an exception after it 258590-image.png

    0 comments No comments

  3. Hadrien FOLLET 21 Reputation points
    2022-11-09T08:23:19.807+00:00

    258568-image.png

    Exception is apparently displayed by the AfxCallWndProc(...) method

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.