Commit 38898e93 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

comdlg32: Use memory allocation helpers.

parent 402fce15
......@@ -32,6 +32,7 @@
#include "commdlg.h"
#include "cderr.h"
#include "wine/debug.h"
#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
......@@ -128,16 +129,17 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
* Success: Pointer to a heap block
* Failure: null
*/
LPVOID COMDLG32_AllocMem(
int size /* [in] Block size to allocate */
) {
LPVOID ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
if(!ptr)
{
COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
return NULL;
}
return ptr;
void *COMDLG32_AllocMem(int size)
{
void *ptr = heap_alloc_zero(size);
if (!ptr)
{
COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
return NULL;
}
return ptr;
}
......
......@@ -31,10 +31,12 @@
#include "winuser.h"
#include "commdlg.h"
#include "dlgs.h"
#include "wine/debug.h"
#include "cderr.h"
#include "cdlg.h"
#include "wine/debug.h"
#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
static INT_PTR CALLBACK ColorDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam );
......@@ -858,7 +860,7 @@ static LRESULT CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
return FALSE;
}
lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );
lpp = heap_alloc_zero(sizeof(*lpp));
lpp->lpcc = cc;
lpp->hwndSelf = hDlg;
......@@ -1215,7 +1217,7 @@ static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
case WM_NCDESTROY:
DeleteDC(lpp->hdcMem);
DeleteObject(lpp->hbmMem);
HeapFree(GetProcessHeap(), 0, lpp);
heap_free(lpp);
RemovePropW( hDlg, szColourDialogProp );
break;
case WM_COMMAND:
......@@ -1326,7 +1328,7 @@ BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
LPWSTR template_name = NULL;
BOOL ret;
LPCHOOSECOLORW lpcc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW));
CHOOSECOLORW *lpcc = heap_alloc_zero(sizeof(*lpcc));
lpcc->lStructSize = sizeof(*lpcc);
lpcc->hwndOwner = lpChCol->hwndOwner;
lpcc->hInstance = lpChCol->hInstance;
......@@ -1338,7 +1340,7 @@ BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
if (!IS_INTRESOURCE(lpChCol->lpTemplateName)) {
INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
template_name = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
template_name = heap_alloc( len * sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, template_name, len );
lpcc->lpTemplateName = template_name;
} else {
......@@ -1350,7 +1352,8 @@ BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
if (ret)
lpChCol->rgbResult = lpcc->rgbResult;
HeapFree(GetProcessHeap(), 0, template_name);
HeapFree(GetProcessHeap(), 0, lpcc);
heap_free(template_name);
heap_free(lpcc);
return ret;
}
......@@ -30,6 +30,7 @@
#include "winuser.h"
#include "wine/unicode.h"
#include "wine/debug.h"
#include "wine/heap.h"
#include "winreg.h"
#include "winternl.h"
#include "commdlg.h"
......@@ -231,7 +232,7 @@ static LONG FD31_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam,
if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
{
if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC))) return FALSE;
if (!(str = heap_alloc(BUFFILEALLOC))) return FALSE;
SendMessageW(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
(LPARAM)str);
......@@ -255,13 +256,13 @@ static LONG FD31_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam,
SetBkColor( lpdis->hDC, oldBk );
SetTextColor( lpdis->hDC, oldText );
}
HeapFree(GetProcessHeap(), 0, str);
heap_free(str);
return TRUE;
}
if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
{
if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
if (!(str = heap_alloc(BUFFILEALLOC)))
return FALSE;
SendMessageW(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
(LPARAM)str);
......@@ -284,13 +285,13 @@ static LONG FD31_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam,
SetTextColor( lpdis->hDC, oldText );
}
DrawIconEx( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hFolder, 16, 16, 0, 0, DI_NORMAL );
HeapFree(GetProcessHeap(), 0, str);
heap_free(str);
return TRUE;
}
if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
{
char root[] = "a:";
if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
if (!(str = heap_alloc(BUFFILEALLOC)))
return FALSE;
SendMessageW(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
(LPARAM)str);
......@@ -318,7 +319,7 @@ static LONG FD31_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam,
SetTextColor( lpdis->hDC, oldText );
}
DrawIconEx( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hIcon, 16, 16, 0, 0, DI_NORMAL );
HeapFree(GetProcessHeap(), 0, str);
heap_free(str);
return TRUE;
}
return FALSE;
......@@ -418,11 +419,11 @@ static LRESULT FD31_DirListDblClick( const FD31_DATA *lfs )
/* get the raw string (with brackets) */
lRet = SendDlgItemMessageW(hWnd, lst2, LB_GETCURSEL, 0, 0);
if (lRet == LB_ERR) return TRUE;
pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
pstr = heap_alloc(BUFFILEALLOC);
SendDlgItemMessageW(hWnd, lst2, LB_GETTEXT, lRet,
(LPARAM)pstr);
strcpyW( tmpstr, pstr );
HeapFree(GetProcessHeap(), 0, pstr);
heap_free(pstr);
/* get the selected directory in tmpstr */
if (tmpstr[0] == '[')
{
......@@ -457,12 +458,12 @@ static LRESULT FD31_FileListSelect( const FD31_DATA *lfs )
return TRUE;
/* set the edit control to the chosen file */
if ((pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
if ((pstr = heap_alloc(BUFFILEALLOC)))
{
SendDlgItemMessageW(hWnd, lst1, LB_GETTEXT, lRet,
(LPARAM)pstr);
SetDlgItemTextW( hWnd, edt1, pstr );
HeapFree(GetProcessHeap(), 0, pstr);
heap_free(pstr);
}
if (lfs->hook)
{
......@@ -624,11 +625,11 @@ static LRESULT FD31_DiskChange( const FD31_DATA *lfs )
lRet = SendDlgItemMessageW(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR)
return 0;
pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
pstr = heap_alloc(BUFFILEALLOC);
SendDlgItemMessageW(hWnd, cmb2, CB_GETLBTEXT, lRet,
(LPARAM)pstr);
wsprintfW(diskname, FILE_specc, pstr[2]);
HeapFree(GetProcessHeap(), 0, pstr);
heap_free(pstr);
return FD31_Validate( lfs, diskname, cmb2, lRet, TRUE );
}
......@@ -729,7 +730,7 @@ static LPWSTR FD31_MapStringPairsToW(LPCSTR strA, UINT size)
if (n < size) n = size;
len = MultiByteToWideChar( CP_ACP, 0, strA, n, NULL, 0 );
x = HeapAlloc(GetProcessHeap(),0, len * sizeof(WCHAR));
x = heap_alloc(len * sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, strA, n, x, len );
return x;
}
......@@ -744,7 +745,7 @@ static LPWSTR FD31_DupToW(LPCSTR str, DWORD size)
LPWSTR strW = NULL;
if (str && (size > 0))
{
strW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
strW = heap_alloc(size * sizeof(WCHAR));
if (strW) MultiByteToWideChar( CP_ACP, 0, str, -1, strW, size );
}
return strW;
......@@ -786,7 +787,7 @@ static void FD31_MapOfnStructA(const OPENFILENAMEA *ofnA, LPOPENFILENAMEW ofnW,
LoadStringW(COMDLG32_hInstance, open ? IDS_OPEN_FILE : IDS_SAVE_AS,
buf, sizeof(buf)/sizeof(WCHAR));
len = lstrlenW(buf)+1;
title_tmp = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
title_tmp = heap_alloc(len * sizeof(WCHAR));
memcpy(title_tmp, buf, len * sizeof(WCHAR));
ofnW->lpstrTitle = title_tmp;
}
......@@ -819,14 +820,14 @@ static void FD31_MapOfnStructA(const OPENFILENAMEA *ofnA, LPOPENFILENAMEW ofnW,
*/
static void FD31_FreeOfnW(OPENFILENAMEW *ofnW)
{
HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrFilter);
HeapFree(GetProcessHeap(), 0, ofnW->lpstrCustomFilter);
HeapFree(GetProcessHeap(), 0, ofnW->lpstrFile);
HeapFree(GetProcessHeap(), 0, ofnW->lpstrFileTitle);
HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrInitialDir);
HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrTitle);
if (!IS_INTRESOURCE(ofnW->lpTemplateName))
HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpTemplateName);
heap_free((void *)ofnW->lpstrFilter);
heap_free(ofnW->lpstrCustomFilter);
heap_free(ofnW->lpstrFile);
heap_free(ofnW->lpstrFileTitle);
heap_free((void *)ofnW->lpstrInitialDir);
heap_free((void *)ofnW->lpstrTitle);
if (!IS_INTRESOURCE(ofnW->lpTemplateName))
heap_free((void *)ofnW->lpTemplateName);
}
/************************************************************************
......@@ -844,9 +845,9 @@ static void FD31_DestroyPrivate(PFD31_DATA lfs)
if (lfs->ofnA)
{
FD31_FreeOfnW(lfs->ofnW);
HeapFree(GetProcessHeap(), 0, lfs->ofnW);
heap_free(lfs->ofnW);
}
HeapFree(GetProcessHeap(), 0, lfs);
heap_free(lfs);
RemovePropA(hwnd, FD31_OFN_PROP);
}
......@@ -918,7 +919,7 @@ static BOOL FD31_GetTemplate(PFD31_DATA lfs)
*/
static PFD31_DATA FD31_AllocPrivate(LPARAM lParam, UINT dlgType, BOOL IsUnicode)
{
PFD31_DATA lfs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FD31_DATA));
FD31_DATA *lfs = heap_alloc_zero(sizeof(*lfs));
TRACE("alloc private buf %p\n", lfs);
if (!lfs) return NULL;
......@@ -940,7 +941,7 @@ static PFD31_DATA FD31_AllocPrivate(LPARAM lParam, UINT dlgType, BOOL IsUnicode)
if (lfs->ofnA->Flags & OFN_ENABLEHOOK)
if (lfs->ofnA->lpfnHook)
lfs->hook = TRUE;
lfs->ofnW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lfs->ofnA->lStructSize);
lfs->ofnW = heap_alloc_zero(lfs->ofnA->lStructSize);
lfs->ofnW->lStructSize = lfs->ofnA->lStructSize;
FD31_MapOfnStructA(lfs->ofnA, lfs->ofnW, lfs->open);
}
......
......@@ -30,6 +30,7 @@
#include "cderr.h"
#include "dlgs.h"
#include "wine/debug.h"
#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
......@@ -284,7 +285,7 @@ static INT_PTR CALLBACK COMDLG32_FindReplaceDlgProc(HWND hDlgWnd, UINT iMsg, WPA
if(iMsg == WM_DESTROY)
{
RemovePropA(hDlgWnd, (LPSTR)COMDLG32_Atom);
HeapFree(GetProcessHeap(), 0, pdata);
heap_free(pdata);
}
return retval;
......@@ -427,7 +428,7 @@ static HWND COMDLG32_FR_DoFindReplace(
error = CDERR_DIALOGFAILURE;
cleanup:
COMDLG32_SetCommDlgExtendedError(error);
HeapFree(GetProcessHeap(), 0, pdata);
heap_free(pdata);
}
return hdlgwnd;
}
......
......@@ -32,6 +32,7 @@
#include "commdlg.h"
#include "dlgs.h"
#include "wine/debug.h"
#include "wine/heap.h"
#include "wine/unicode.h"
#include "cderr.h"
#include "cdlg.h"
......@@ -1151,11 +1152,11 @@ static LRESULT CFn_WMDestroy(HWND hwnd, LPCHOOSEFONTW lpcfw)
if((lpcfw->Flags & CF_USESTYLE) && lpcfw->lpszStyle) {
len = WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, NULL, 0, 0, 0);
WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, lpcfa->lpszStyle, len, 0, 0);
HeapFree(GetProcessHeap(), 0, lpcfw->lpszStyle);
heap_free(lpcfw->lpszStyle);
}
HeapFree(GetProcessHeap(), 0, lpcfw->lpLogFont);
HeapFree(GetProcessHeap(), 0, lpcfw);
heap_free(lpcfw->lpLogFont);
heap_free(lpcfw);
SetPropW(hwnd, strWineFontData, 0);
return TRUE;
......@@ -1217,16 +1218,16 @@ static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
lpcfa=(LPCHOOSEFONTA)lParam;
SetPropW(hDlg, strWineFontData_a, (HANDLE)lParam);
lpcfw = HeapAlloc(GetProcessHeap(), 0, sizeof(CHOOSEFONTW));
lpcfw = heap_alloc(sizeof(*lpcfw));
memcpy(lpcfw, lpcfa, sizeof(CHOOSEFONTA));
lpcfw->lpLogFont = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGFONTW));
lpcfw->lpLogFont = heap_alloc(sizeof(*lpcfw->lpLogFont));
memcpy(lpcfw->lpLogFont, lpcfa->lpLogFont, sizeof(LOGFONTA));
MultiByteToWideChar(CP_ACP, 0, lpcfa->lpLogFont->lfFaceName,
LF_FACESIZE, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE);
if((lpcfa->Flags & CF_USESTYLE) && lpcfa->lpszStyle) {
len = MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, NULL, 0);
lpcfw->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
lpcfw->lpszStyle = heap_alloc(len * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, lpcfw->lpszStyle, len);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment