|
-
Jan 28th, 2002, 07:04 AM
#1
Thread Starter
Hyperactive Member
Ansi/unicode
If I want my application's character set to be neutral (as opposed
to strictly ANSI or UNICODE), I'm aware of the declaration of
TCHARs instead of CHARs and using functions such as _tcscat
instead of strcat, what else would I have to do for the
preprocessor exactly to be able to switch between an ANSI
and a UNICODE build?
Thanks
Bababooey
Tatatoothy
Mamamonkey
-
Jan 28th, 2002, 01:24 PM
#2
Monday Morning Lunatic
Somewhere in the compiler options (Project Settings->Preprocessor in VC++) you need to remove MBCS and put UNICODE and _UNICODE (both of them, note the second has the preceding underscore).
Here's some little bits of code that might be useful if you use the STL under Windows at all...
Code:
#ifdef UNICODE
typedef wstring tstring;
#else
typedef string tstring;
#endif
string WideToANSI(wstring sIn) {
int iReq = WideCharToMultiByte(CP_ACP, 0, sIn.c_str(), -1, NULL, 0, NULL, NULL);
char *pcBuf = new char[iReq];
WideCharToMultiByte(CP_ACP, 0, sIn.c_str(), -1, pcBuf, iReq, NULL, NULL);
string sTemp = pcBuf;
delete[] pcBuf;
return sTemp;
}
wstring ANSIToWide(string sIn) {
int iReq = MultiByteToWideChar(CP_ACP, 0, sIn.c_str(), -1, NULL, 0);
wchar_t *pcBuf = new wchar_t[iReq];
MultiByteToWideChar(CP_ACP, 0, sIn.c_str(), -1, pcBuf, iReq);
wstring sTemp = pcBuf;
delete[] pcBuf;
return sTemp;
}
tstring EnsureTStr(string sIn) {
#ifndef UNICODE
return sIn;
#else
return ANSIToWide(sIn);
#endif
}
tstring EnsureTStr(wstring sIn) {
#ifdef UNICODE
return sIn;
#else
return WideToANSI(sIn);
#endif
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 28th, 2002, 01:56 PM
#3
Thread Starter
Hyperactive Member
Bababooey
Tatatoothy
Mamamonkey
-
Jan 28th, 2002, 02:03 PM
#4
And if you are too lazy to set both UNICODE and _UNICODE:
Code:
#ifdef UNICODE
#ifndef _UNICODE
#define _UNICODE
#endif
#endif
#ifdef _UNICODE
#ifndef UNICODE
#define UNICODE
#endif
#endif
Write that before you inclue ANY headers.
Also make sure that you use _tmain/_tWinMain. To make such apps working you should also write this:
#ifdef UNICODE
// this if you are writing a console app
#pragma comment(linker, "/entry:\"wmainCRTStartup\"")
// this if you are writing a GUI app
#pragma comment(linker, "/entry:\"wWinMainCRTStartup\"")
#else
// this if you are writing a console app
#pragma comment(linker, "/entry:\"mainCRTStartup\"")
// this if you are writing a GUI app
#pragma comment(linker, "/entry:\"WinMainCRTStartup\"")
#endif
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|