[2/2] oleacc: implemented GetRoleText[A/W] with tests

Dmitry Timoshkov dmitry at codeweavers.com
Sun Oct 5 00:51:38 CDT 2008


"Nikolay Sivov" <bunglehead at gmail.com> wrote:

> +UINT WINAPI GetRoleTextA(DWORD role, LPSTR lpRole, UINT rolemax)
> +{
> +    UINT length;
> +    WCHAR *roletextW;
> +    CHAR *roletextA;
> +
> +    TRACE("%u %p %u\n", role, lpRole, rolemax);
> +
> +    length = GetRoleTextW(role, NULL, 0);
> +    if(length == 0)
> +        return 0;
> +
> +    roletextW = HeapAlloc(GetProcessHeap(), 0, (length + 1)*sizeof(WCHAR));
> +    if(!roletextW)
> +        return 0;
> +
> +    GetRoleTextW(role, roletextW, length + 1);
> +
> +    length = WideCharToMultiByte( CP_ACP, 0, roletextW, -1, NULL, 0, NULL, NULL );
> +
> +    if(!lpRole){
> +        HeapFree(GetProcessHeap(), 0, roletextW);
> +        return length - 1;
> +    }
> +
> +    roletextA = HeapAlloc(GetProcessHeap(), 0, length);
> +    WideCharToMultiByte( CP_ACP, 0, roletextW, -1, roletextA, length, NULL, NULL );
> +
> +    if(rolemax < length)
> +        length = rolemax;
> +
> +    memcpy(lpRole, roletextA, length);
> +    lpRole[length-1] = '\0';
> +
> +    HeapFree(GetProcessHeap(), 0, roletextA);
> +    HeapFree(GetProcessHeap(), 0, roletextW);
> +
> +    return length - 1;
> +}

Why do you need to allocate an intermediate roletextA?

-- 
Dmitry.



More information about the wine-devel mailing list