Click to See Complete Forum and Search --> : Unicode Porting Issues !!


santoshthankach
May 26th, 2006, 03:45 AM
Hi All,

I have function like follows:

void XYZ(char *format,...)
{
...
va_list list;
char temp[256];

va_start( list, format );
vsprintf( temp, format, list );
...

}

I need to port this function into unicode, i.e. "format" can have string containing characters from other languages. Do we have some unicode compliant (multi byte) version of APIs: va_start(), vsprintf() that can get 2 byte characters.

I did tried using "wchar_t" instead of "char" and code did got compiled after that but is the correct way of doing this.

Please let me know of your suggestions.

Thanks in advance,
Santosh Thankachan

ovidiucucu
May 26th, 2006, 05:38 AM
The UNICODE version of vsprintf is vswprintf. va_list and va_start can be used also in UNICODE.
void FormatW(wchar_t*& buffer, const wchar_t* format,...)
{
va_list args;
va_start(args, format);
vswprintf(buffer, format, args);
}

// somehwere call...
wchar_t* buffer = new wchar_t[128];
FormatW(buffer, L"XXX-%s-XXX{{ΘΗ", L"ASDFGHJKL");
// ...
delete []buffer;
Now, to asure it compile in both UNICODE and non-UNICODE, use the macros defined in TCHAR.H (_vstprintf, _T, and so on).

void FormatT(LPTSTR& buffer, LPCTSTR format,...)
{
va_list args;
va_start(args, format);
_vstprintf(buffer, format, args);
}

// somehwere call...
LPTSTR buffer = new TCHAR[128];
FormatT(buffer, _T("XXX-%s-XXX{{ΘΗ"), _T("ASDFGHJKL"));
// ...
delete []buffer;

santoshthankach
May 26th, 2006, 06:48 AM
Thanks ovidiu,

I have already started using the same. Thanks for your code snippet.

Santosh