From c5b27fa97b4e9412f8a0483ff3b16e25b606f437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Zalewski?= Date: Wed, 19 Apr 2006 14:34:14 +0200 Subject: [PATCH] comctl32: Add Str_SetPtrWtoA analogue to Str_SetPtrAtoW. --- dlls/comctl32/comctl32.h | 1 + dlls/comctl32/comctl32undoc.c | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/dlls/comctl32/comctl32.h b/dlls/comctl32/comctl32.h index 8053accb36f..005089dc99e 100644 --- a/dlls/comctl32/comctl32.h +++ b/dlls/comctl32/comctl32.h @@ -145,6 +145,7 @@ VOID COMCTL32_RefreshSysColors(void); void COMCTL32_DrawInsertMark(HDC hDC, const RECT *lpRect, COLORREF clrInsertMark, BOOL bHorizontal); INT Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen); BOOL Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc); +BOOL Str_SetPtrWtoA (LPSTR *lppDest, LPCWSTR lpSrc); #define COMCTL32_VERSION_MINOR 80 #define WINE_FILEVERSION 5, COMCTL32_VERSION_MINOR, 0, 0 diff --git a/dlls/comctl32/comctl32undoc.c b/dlls/comctl32/comctl32undoc.c index 2812e34f87b..e678cada774 100644 --- a/dlls/comctl32/comctl32undoc.c +++ b/dlls/comctl32/comctl32undoc.c @@ -1107,6 +1107,46 @@ BOOL Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc) return TRUE; } +/************************************************************************** + * Str_SetPtrWtoA [internal] + * + * Converts a unicode string to a multi byte string. + * If the pointer to the destination buffer is NULL a buffer is allocated. + * If the destination buffer is too small to keep the converted wide + * string the destination buffer is reallocated. If the source pointer is + * NULL, the destination buffer is freed. + * + * PARAMS + * lppDest [I/O] pointer to a pointer to the destination buffer + * lpSrc [I] pointer to a wide string + * + * RETURNS + * TRUE: conversion successful + * FALSE: error + */ +BOOL Str_SetPtrWtoA (LPSTR *lppDest, LPCWSTR lpSrc) +{ + TRACE("(%p %s)\n", lppDest, debugstr_w(lpSrc)); + + if (lpSrc) { + INT len = WideCharToMultiByte(CP_ACP,0,lpSrc,-1,NULL,0,NULL,FALSE); + LPSTR ptr = ReAlloc (*lppDest, len*sizeof(CHAR)); + + if (!ptr) + return FALSE; + WideCharToMultiByte(CP_ACP,0,lpSrc,-1,ptr,len,NULL,FALSE); + *lppDest = ptr; + } + else { + if (*lppDest) { + Free (*lppDest); + *lppDest = NULL; + } + } + + return TRUE; +} + /************************************************************************** * Notification functions