Re: Output ANSI text from generic code
- From: "Mitch Gallant" <jensigner@xxxxxxxxxxxxxxxx>
- Date: Tue, 17 Feb 2009 15:48:26 -0400
"Giovanni Dicanio" <giovanniDOTdicanio@xxxxxxxxxxxxxxxxx> wrote in message
news:uztEYYRkJHA.4760@xxxxxxxxxxxxxxxxxxxxxxx
"Mitch Gallant" <jensigner@xxxxxxxxxxxxxxxx> ha scritto nel messaggio
news:eAEk$rPkJHA.4880@xxxxxxxxxxxxxxxxxxxxxxx
My app is a C windows application which I'd prefer to keep as C. However
I did try T2A and it worked perfectly after changing the code to .cpp
from .c and recompiling with the required atl headers.
I suggested CT2A, which I prefer instead of T2A.
CT2A has been being available since VS2003 (a.k.a. VC7.1), instead T2A was
something from VC6 (ATL3).
CT2A has some advantages over T2A, as you can read from a comparison table
shown here:
http://msdn.microsoft.com/en-us/library/87zae4a3(VS.80).aspx
"Old ATL 3.0 Conversion Macros" vs. "New ATL 7.0 Conversion Classes"
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?
I believe that the performance of your app won't change as a result of
this simple C++ recompilation :)
Your new .CPP app will be just fine.
Any other issues with changing from C to CPP from original C code?
I think that you will just have a cleaner code, and better type checking.
In fact, the C++ compiler tends to be more careful about strict type
checking than a pure C compiler, so I think that if you "write C code" in
.cpp files and so use the C++ compiler to build the final binary, you may
have an increased quality in your source code.
I think that C++ is a very complex language, but you don't need to be a
"language lawyer" to be productive with it (unless you want to develop
some core library like STL!).
The first step is to just take your C code, rename the file to .cpp, and
do a rebuild. If the C++ compiler complains about errors or warnings, they
may be due to type mismatch and stricter C++ type checking. So, trying to
fix your C code to compile as C++ code without errors and warnings will
increase the quality of your code.
Next step would be to refactor your code, moving data structures and
global functions into proper classes and methods. Data structure fields
become class data members, and functions related to some data structures
become methods of that class (sort of).
This is another step in the direction of making your code of better
quality.
Then you can use other tools that C++ offers, like inheritance, templates,
exceptions for error management, etc.
Regarding my original question, the motivation was that I want the
text-generic application to always write out ANSI text files .. not
UNICODE.
I consider that safe only if you use pure American text (i.e. a-Z, 0-9,
etc.).
If you start using Italian accented characters like è é ò etc. or
something from Japanese or Chinese, or Greek letters, etc. I think that
ANSI/MBCS becomes a kind of "pseudo-random" format to store text (you will
become dependent upon code pages, etc.).
Unicode (be it UTF-8 or UTF-16) is a cleaner solution to store
internatinal text, IMHO.
Thanks for all this information. As Ulrich suggested, I think I'll implement
a function like:
void stringToAnsi(char *ansistring, TCHAR const* tstring)
and use
#ifdef UNICODE
WideCharToMultiByte(CP_UTF8, ....)
#else
lstrcpy(...)
#endif
This is for a log file to save the information from several DialogBox Text
Controls, which may be compiled with UNICODE. The tstring values are from
GetDlgItemText(..).
I have done quite a bit of Java and C#.net programming in the past .. but
not much C++.
- Mitch
.
- References:
- Output ANSI text from generic code
- From: Mitch Gallant
- Re: Output ANSI text from generic code
- From: Giovanni Dicanio
- Re: Output ANSI text from generic code
- From: Mitch Gallant
- Re: Output ANSI text from generic code
- From: Giovanni Dicanio
- Output ANSI text from generic code
- Prev by Date: Re: Defining a comment
- Next by Date: Genuinely local objects (from Stroustrup's FAQ)
- Previous by thread: Re: Output ANSI text from generic code
- Next by thread: Re: Output ANSI text from generic code
- Index(es):
Relevant Pages
|