Re: UNICODE Portierung

From: Martin Richter [MVP] (martin.richter_at_grutzeck.de)
Date: 08/25/04


Date: Wed, 25 Aug 2004 11:23:18 +0200

Hallo Sebastian!

> ->Ich will meine alten, für Win98 geschriebenen Progeramm auf
> Win2000/XP portieren, also auch UNICODE fähig machen.
>
> Was habe ich dabei zu beachten (welche defines brauche ich für die
> MFC)?

Den _UNICODE natürlich und _MBCS darf nicht gesetzt sein. Das ganze
natürlich am besten in den Projekt seetings

> Was muss ich bei char beachten (TCHAR /WCHAR/...)

WCHAR ist wchar_t.
TCHAR ist char wenn _UNICODE nicht definiert ist und wchar_t wenn _UNICODE
definiert ist.
Die TCHAR Definitionen eignen sich ideal für Sourcen, die sowohl mit als
auch ohne Unicode laufen sollen.

> Gibt es außer bei Stringfunktionen noch anderswo Fallstricke?

Millionen.
Der häufigste ist sizeof um die Größe eines Ausgabepuffers zu ermitteln,
hier wird aber von Windows erwartet, das die Anzahl der Zeichen übergeben
wird. In Unicode Kompilaten ist also diese Zahl dann doppelt so groß.
sizeof(buff)/sizeof(TCHAR) funktionniert immer.

-- 
Martin Richter [MVP] WWJD
"In C we had to code our own bugs. In C++ we can inherit them."
 FAQ : http://www.mpdvc.de
 Samples: http://www.codeguru.com http://www.codeproject.com


Relevant Pages

  • Re: Window types
    ... typedef WCHAR TCHAR, * PTCHAR; ... typedef char TCHAR, * PTCHAR; ... Under a Unicode build, ... If the only text your app needs to deal with can be handled with ASCII ...
    (microsoft.public.vc.language)
  • Re: TCHAR and buffer overflows
    ... > This would be a problem if you hadn't defined UNICODE in your build. ... > Check your factory headers for TCHAR defs and such, ... checked whether the MSVCRT memcpyimplementation actually detects overlapping ... Or good tools, lousy user, lousy work. ...
    (comp.security.misc)
  • Re: TCHAR and buffer overflows
    ... > This would be a problem if you hadn't defined UNICODE in your build. ... > Check your factory headers for TCHAR defs and such, ... checked whether the MSVCRT memcpyimplementation actually detects overlapping ... Or good tools, lousy user, lousy work. ...
    (comp.os.ms-windows.nt.admin.security)
  • Re: VC2005 Pro: IDE (Compiler ?) cant find Stdafx.h
    ... For new code I would obviously use UNICODE but for existing stuff ... > Use Multi-Byte Character Set ... > If you use TCHAR etc., and want your code to run on another platform, then ... > typedef char TCHAR; ...
    (microsoft.public.vc.language)
  • Re: TCHAR and buffer overflows
    ... This would be a problem if you hadn't defined UNICODE in your build. ... unsigned char *_mbsncpy(unsigned char *strDest, ... >> macro WCHAR was introduced to switch between ascii and unicode chars as ... > I think you mean TCHAR. ...
    (comp.os.ms-windows.nt.admin.security)

Loading