Wine Developer Cheatsheet, v1

Rolf Kalbermatter rolf.kalbermatter at citeng.com
Mon Sep 6 13:04:55 CDT 2004


"Diego 'Flameeyes' =?ISO-8859-1?Q?Petten=F2?=" wrote:

>I have only a doubt:
>
>> - Is it possible to implement the ANSI version by converting to unicode
>>    then calling the wide version, rather than duplicate it?
>
>How can I convert an ansi string to a unicode one and reverse? So I can redo
>the patch with the calls :)

Typically you use MultiByteToWideChar() for any input strings and then
WideCharToMultiByte() for possible output strings. You can look at
shlwapi/path.c and other files in there to see how this is usually done.

Depending on the place where you do it, it might be preferable to use
dynamically allocated buffers instead of using stack space as Wine is
already using quite a lot of stack. Principle:

    WCHAR *textW;
    INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
    if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
    {
        MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW);

        /* Do the Widechar call */
  
        HeapFree(GetProcessHeap(), 0, textW);
    }

Rolf Kalbermatter
 





More information about the wine-devel mailing list