0

I have three C++Builder 11 Win32 applications that I have inherited. They all use MBCS and not UNICODE. However, in only one of the 3, UNICODE and MBCS is defined in the debug build only. Of course, this is causing compile errors.

I have checked the project conditional defines and UNICODE is not defined. I have searched all project files and cannot find UNICODE defined anywhere. I am new to Embarcadero, so I hope I am missing something obvious that is causing this. does anyone have an idea of where UNICODE may be getting defined?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • It may be in the VCL/RTL source code. Did you try using the IDE's Find in Files functionality? Point it at the EMBT source folders (so it will search both the RTL and VCL source), and search for DEFINE UNICODE. The entire RTL and VCL are both UNICODE since Delphi 2009 was released. – Ken White Jun 04 '23 at 02:12
  • Also, if you inherited them, why didn't the original developer have this issue? It sounds like either you've configured something incorrectly, or the previous developer passed on non-working code to you. I'm not sure how they would have disabled UNICODE - as I said, the entire RTL and VCL have used Unicode for more than a decade now. – Ken White Jun 04 '23 at 02:14
  • I have used find in files and nothing is found. I put test statements in the code to verify if _MBCS and UNICODE were defined. In the release build, only _MBCS is defined while in the debug build, both are defined. – user22015813 Jun 05 '23 at 04:01
  • I believe that the person that I inherited from only converted this project to a newer version of Builder and never tried to build or run it. Changes were made to the other 2 projects at that time, but not this one. I have verified that UNICODE is not defined in the other 2 projects. – user22015813 Jun 05 '23 at 04:03
  • @KenWhite the RTL/VCL is written in Delphi which doesn't care about the `UNICODE` conditional (and consequently the `TCHAR` type), they only affect C++. – Remy Lebeau Jun 05 '23 at 14:54
  • @user22015813 the best way to handle this is to simply write code that doesn't depend on `UNICODE` at all. Don't use the `TCHAR` type and `TCHAR`-related APIs at all. If you have narrow string data, use `char` and `xxxA` APIs directly. If you have wide string data, use `wchar_t` and `xxxW` APIs directly. I know, easily said than done for legacy migrated code, but pretty easy to follow in new code. – Remy Lebeau Jun 05 '23 at 15:00
  • The code does not support UNICODE. This is the issue. I do not want UNICODE defined but it is which is causing compile errors since the code is written for MBCS. Actually in the debug config, both MBCS and UNICODE are defined, but I cannot fine where UNICODE is defined. – user22015813 Jun 06 '23 at 16:29

1 Answers1

0

Double check the "_TCHAR maps to" option in your project setup for every build configuration. UNICODE is defined when TCHAR maps to the wchar_t type (which is the default for new projects since 2009, but not for migrated projects that were created pre-2009).

Values of the '_TCHAR maps to' Option:

value meaning
char Substitutes char for _TCHAR.

Note: This option does not float to wide definitions of standard library and API functions.

wchar_t - Substitutes wchar_t for _TCHAR.

- Sets both the UNICODE and _UNICODE macro constants.

- Floats to the wide definitions of standard library and API functions.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770