I've recently been forced to change my project from using a MBCS to Unicode. This has thrown up a number of problems with my code one of which is below.
text.Format ("Row %d,Col %d",ln,col);
Thats is the line that I had in when using MBCS, I know how to format strings etc under unicode, and the problem isnt the change, it is what would that string appears as under MBCS, I cant seem to find much on what the %d thing would do, so if some one could tell me how the string text would appear after that code was successful, that would be great
Thanks
Will

CString::Format issue
Normality2000
Nearly all functions exists in a Unicode and a MBCS version! You have to take care about this. If you don't take care you get thousands of errors.
Note also that nearly all Windows API functions exist in two versions a MBCS and a Unicode version (SetWindowTextA and SetWindowTextW).
So every string constant not defined with _T used in a function that maps to Unicode (like SetWindowText) will cause an error!
Just search the MSDN for tchar, you find this link:
http://msdn.microsoft.com/library/default.asp url=/library/en-us/vccore/html/_core_generic.2d.text_mappings_in_tchar..h.asp
KBaghaei
Michael Tsai
There is one file called martin.cpp
and two projects, project 1 uses unicode and project 2 uses MBCS. But both projects use the file martin.cpp. This would cause the problem because to get the file to compile under project 1 it would have to use the unicode versions of the API but to get it to compile under project 2 it would have to use the MBCS versions of the API. So u see thats why i get the error, becuase the file martin.cpp can be one not the other. I would have to have one file for MBCS and one for unicode. Under these circumstances of sharing the file i would get the error correct
Will
Mr. Jerzy
correct
Will
Kerberos Mansour
And again if I use just the MBCS versions and the correct string constants I would get no errors neither in an MBCS project nor in an Unicode project!
You get problems because you never cared about the different MBCS and Unicode versions of the API!
Emphyrio
Incidently is there a really good article you know of on this I can find some, but nothing great
Will
larkahn
Thats what I just said, i'm saying the reason why it failed is because the two are mixed, its not a solution its the reason why the error is there in first place. I agree
MickT
Rui Silva18093
If martin.cpp just contains this code and function:
This function will work always:
void FooA()
{
MessageBoxA(NULL, "MyFoo", "MyFoo", MB_OK);
}
The next too:
void FooW()
{
MessageBoxW(NULL, L"MyFoo", L"MyFoo", MB_OK);
}
And this also
void FooT()
{
MessageBox(NULL, _T("MyFoo"), _T("MyFoo"), MB_OK);
}
BUT THIS WILL FAIL IN A UNICODE COMPILE
void FooFail()
{
MessageBox(NULL, "MyFoo", "MyFoo", MB_OK);
}
Because MessageBox will map to MessageBoxW!
So what can you do:
1. So use either always the Unicode versions
2. Use always the MBCS versions
3. Use the tchar versions.
Never mix!
vtcoder
text.Format (L"Row %d,Col %d",ln,col);
or
text.Format (_T("Row %d,Col %d"),ln,col);
I would prefer the later one, because it allows a project to be dynamically changed from MBCS to UNICODE and vice versa!