A Solution which contents 3 projects and below are the names & their character set encoding type
1. Utility – > MBCS
2. Calculations -> MBCS
3. User Interface -> Unicode ( Earlier It used to be MBCS)
WhenChanged the Character set encoding for User Interface and compiled the code, you will get hte Errors for the Char type that corrected all of then and made them Wide characters.
When the project gets compiled but it gives Linker errors. Can you please let me know Do I need to convert all the Projects to use Unicode character set ?
Replies:
FIRST, you can mix Unicode and MBCS modules, if you keep the interface between them *clear*.
e.g. if you just specify CString in the interface between module, this is *not* clear and unambigous; in fact, CString is "ambigous", because it can be considered CStringA (MBCS) or CStringW (Unicode) basing on build options.
This is the same with e.g. LPCTSTR, or TCHAR.
You can’t use LPCTSTR or TCHAR or CString at the *interface* between modules that are ANSI (MBCS) on one side and Unicode on the other side.
So, on the interface, you must explicit qualify the string type, e.g. using CStringA or CStringW, or wchar_t, or char, etc. …
For example, suppose that you have in Utility (ANSI) a function that you want to use in UserInterface module (Unicode). You must use an explicit unambigous prototype like so for Utility function:
void Utility_ProcessString( const char * string );
// or:
// void Utility_ProcessString( const CStringA & string );
Of course, in UserInterface you can convert a Unicode string to MBCS and pass the converted string (const char*) to Utility_ProcessString.
BUT, Converting the interface is usually a much bigger job than converting the complete project to UNICODE. You should have a very very good reason to mix MBCS and UNICODE in the same project. I can not think of one.
But mixing UTF-8 and UTF-16 can be a valid strategy, and involves much the same issues. Unicode UTF-8 is good for storage (e.g. in XML files, or when sending string data through Internet), while UTF-16 is good for processing and use inside an app (being also Windows "native" Unicode format).
Tags: Link error, MBCS, UNICODEPermalink: Code Library - Link error when mix MBCS and Unicode in ONE project
Subcribe the update with Google Reader.
RSS feed for comments on this post · TrackBack URI
Leave a reply