Sorry that I got into this thread so late!  :-)

> I have recently tried to build one of my applications in a unicode
> configuration (by setting the character set in the configuration
> properties in the general page to 'unicode', I assume that defines the
> UNICODE and _UNICODE macros for me?).
> It's the first time I worked with it and so far it's been...
> let's say 'interesting'.
> I read the chapter on Unicode in the 5th edition of the Petzold and
> the msdn general unicode documentation and that helped me through most
> problems. However I now have the problem that I have a library (a C
> dll) that want its arguments as const char* 's. I use ATL's CString
> throughout my program and I was wondering if there is any unicode
> conversion support in CString. What I do now is in the line of the
> following:
>
> CString str("hello");
> char* tmp = (char*)malloc(str.GetLength() + 1); wcstombs(tmp, str,
> str.GetLength()); LibraryFuncCall(tmp); free(tmp);

There's a much more easier way:

#include <altconv.h>

 void g(char const*);
 void f(CString const & str)
 {
  USES_CONVERSION;
  g( T2CA( str ) );
 }

> but as you can see this is a lot of work and it makes the code longer.
> Is there a shorter way? Also, wcstombs stands for 'wide character to
> multi-byte string' I believe; can I always (for applications with
> western codepages) consider 'multi-byte' to be 'ascii' ? Sorry if this
> mail reads confused, it's probably because I am ;) Thanks.

Well, I can tell you that I have shipped several apps which were fully Unicode
(neither of them even had an English interface) and I have never used such low
level stuff as wcstombs or WideCharToMultiByte.  ATL's conversion macros have
always been sufficient to me.

Another note, ASCII is a "Single-Byte Character Set" (SBCS), not MBCS.  MBCS
encoding requires special processing.  For example, the following strlen
implementation won't work for MBCS:

 size_t strlen(char const * p)
 {
  size_t len = 0;
  while (*p ++) ++ len;
  return len;
 }

I have two articles on Unicode, which I suggest you take a look at them.  You
can find both at: http://www.beginthread.com/Ehsan/ViewAllArticles .

If you had more questions about SBCS/MBCS/Unicode after reading those
articles, please let me know.

-------------
Ehsan Akhgari

Farda Technology (http://www.farda-tech.com/)

List Owner: [EMAIL PROTECTED]

[ Email: [EMAIL PROTECTED] ]
[ WWW: http://www.beginthread.com/Ehsan ]

With one's principles one seeks to tyrannize over one's habits or to justify
or honour or scold or conceal them - two people with the same principles
probably seek something fundamentally different with them.
-Beyond Good And Evil, F. W. Nietzsche





Reply via email to