Re: Output ANSI text from generic code
Mitch Gallant wrote:
Regarding changing a windows C application to cpp and recompiling, if I
don't introduce any classes or CPP code in the original C code (except say
for the T2A or CT2A macros) and rcompile as .cpp, does the resultant
compiled/linked code change significantly in a way that migh changed a
"real-time" (i.e. waveform sampling) application? Any other issues with
changing from C to CPP from original C code?
C is not C++. C code that has to pass a C++ compiler always looks like junk,
whether you look at it as C or C++ doesn't matter. E.g. casting malloc() is
discouraged in C, whereas in C++ you should use a static_cast. However,
using malloc() in C++ is typically a mistake anyway, using std::vector is
typically the better alternative.
If all you want is to convert a string, write a function:
char* string_to_ansi(TCHAR const* str);
Implement it with WideCharToMultibyte() and just don't forget to release the
returned buffer afterwards. The mentioned macros do the same, only that the
destructor of the created object will release the resources.
Regarding my original question, the motivation was that I want the
text-generic application to always write out ANSI text files .. not
UNICODE.
Two suggestions here:
1. Don't base your internal application logic on TCHAR.
2. For win32 interaction, use WCHAR exclusively.
The first means that even though you use TCHAR for file paths (things that
depend on the win32 interface) you still write files in whatever format
best suits your application, logfiles typically in ASCII, for other files I
would suggest UTF-8.
The second one means that since MS Windows 95 and other MS Windows variants
like that are long dead and buried, you can and IMHO should use the WCHAR
APIs that further provide full Unicode support for paths and UIs. Using
TCHAR was a hack to help transitioning to WCHAR natively, but I wouldn't
use that any longer.
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch??ftsf??hrer: Thorsten F??cking, Amtsgericht Hamburg HR B62 932