[unixODBC-support] Unicode and Wide Char strings

Nick Gorham nick at lurcher.org
Tue Oct 19 11:28:31 BST 2010


Neha Avasthy wrote:
> Thanks Nick.
>
> The code that I have has numerous such assignments to TCHAR using the 
> _T macro
>
> #define _T(x) __T(x)
> #define __T(x) L##x
>
> I want to try something that requires minimal changes in the source 
> code and that can be altered at the macro level only for ex.
>
> #define _T(x) __T(x)
> #define __T(x) Copy_to_Unicode (x)
>
> But not sure how this function Copy_to_Unicode will look like . Is it 
> something like mbstowcs () calls.

Something like (probably full of bugs, just a first stab)

#define _T(x) __T(x)
#define __T(x) (__copy_to_unicode(alloc( strlen((x))*sizeof(TCHAR)), 
strlen((x)), (x)))

TCHAR *__copy_to_unicode( TCHAR *dest, int dest_len, char *src )
{
    TCHAR *ptr = dest;

    while( *src && dest_len > 0 ) {
          *ptr++ = *src++;
          dest_len --;
    }
    *ptr = 0;

    return dest;
}

-- 
Nick


More information about the unixODBC-support mailing list