Re: Optimization of code

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Over the last 20 years, a significant fraction of my revenue has come from controlling
external devices that take 8-bit character string commands. Only at the lowest level do I
convert Unicode to ANSI. If I get the notification that there was an unconvertible
character, I return from the call with an INVALID_PARAMETER type error, e.g.,

BOOL CMyDocument::SendToDevice(const CString & data)
{
CStringA command;
#ifdef _UNICODE
BOOL error;
int size = ::WideCharToMultiByte(CP_ACP, ...flags..., (LPCWSTR)data, -1, NULL, 0,
"?", &error);
if(!error)
{
LPSTR p = command.GetBuffer(size);
::WideCharToMultiByte(CP_ACP, ...flags..., (LPCWSTR)data, -1, p, size, "?",
&error);
}
if(error)
{
::SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
#else
command = data;
#endif
...send data to device...(asks asynch thread to do it)
return TRUE;
}

Note that I explicitly call WCTMB because I want the ability to see if there was an error,
and although T2A would be shorter code, it would be less robust. Since the particular
product is international (and they have customers in China, Japan and Korea), I've been
told this test actually caught some errors, particularly for the new line of controllers
that would accept character data, but only 8-bit data (which they displayed). They tell
me a future release will accept UTF-8 and they will enhance the LCD display to allow
localization, but that won't be for a couple more years.
joe
****
On Fri, 04 Sep 2009 09:09:31 -0400, r norman <r_s_norman@xxxxxxxxxxx> wrote:

There exist many external devices that programs must communicate with
that require ASCII text strings as part of their protocol. Often
these have to be parsed for processing and character-by-character
manipulation alone would be a terrible burden. I can easily accept
switching to Unicode for all processes contained purely within the
local machine but it would be a disaster to lose ANSI support
altogether.

On Thu, 3 Sep 2009 23:41:30 -0700, "Tom Serface" <tom@xxxxxxxxxxxxx>
wrote:

I've started just going to Unicode only and forgetting about the stupid _T()
stuff (just using L"" instead). I wish, like C#, I didn't even have to do
that and it could just assume Unicode for all strings, but ... I don't see
any good reason to use ANSI any longer and on the off chance I really need a
char based array I can always just use char. I think it's time to skinny
down MFC and just lose ANSI support altogether, but, like you, I'm not
holding my breath.

Tom

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:07c1a5l8nb9ilamcevstaotfo1inaqsllj@xxxxxxxxxx
Sorry. TCHAR and the entire tchar.h existed and I used them extensively
in VS6. I've
been writing Unicode-aware code with TCHAR and tchar.h since VS4.2; they
may have existed
before that point, but that's when I started becoming Unicode-aware. What
was missing was
CStringA/CStringW distinctions. which was a real pain.

I keep forgetting how primitive the MFC library and C++ compiler were in
VS6. So the
choices currently are a great IDE and crappy language/library, or a crappy
IDE and a great
language/library. It shouldn't have been so hard to get great in both!

If we can just get the cuteness factor and the designers' egos out of the
equation, we
might actually start to see usable software come out from Microsoft again.
But I'm not
holding my breath for that.
joe

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Unicode Support
    ... > Not knowing much about UTF-8 (my Unicode knowledge extends as far as ... > literal strings of this form as long as the character code for quote ... > can never appear in a MBCS (multibyte character sequence). ... then XP Notepad directly understands UNICODE and you can ...
    (alt.lang.asm)
  • Re: ways to check for octets outside of the safe ASCII range?
    ... and works properly against Unicode strings. ... Space is an ordinary single-width character like any other, ... Unicode implementation. ... If these people are not aware that Perl scalars don't necessarily ...
    (comp.lang.perl.misc)
  • Re: UTF8 conversion
    ... Firefox) to convert Javascript's strings (two byte ... unicode) to/from UTF8: ... There is no such thing as a "two-byte unicode character". ... not encode it using encodeURI which will change ...
    (comp.lang.javascript)
  • Wide character notation, was Re: How to NOT use utf8.
    ... > So the author suggests that there may be a problems for unicode, ... in the Perl documentation). ... The Unicode code for the desired character, in hexadecimal, ... Unicode strings ...
    (comp.lang.perl.misc)
  • Program works great, except under less, cron or execl (Unicode?)
    ... I have a program which works great when run from the command line. ... - piping it through less ... I'd post the whole program here, except it involves weird Unicode ... strings. ...
    (comp.lang.python)