2 * Win32 heap definitions
4 * Copyright 1996 Alexandre Julliard
15 #include "wine/unicode.h"
16 #include "wine/windef16.h" /* for SEGPTR */
18 extern SEGPTR
HEAP_GetSegptr( HANDLE heap
, DWORD flags
, LPCVOID ptr
);
20 /* SEGPTR helper macros */
22 #define SEGPTR_ALLOC(size) \
23 (HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, (size) ))
24 #define SEGPTR_NEW(type) \
25 ((type *)HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, sizeof(type) ))
26 #define SEGPTR_STRDUP_WtoA(str) \
27 (HIWORD(str) ? HEAP_strdupWtoA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
28 #define SEGPTR_FREE(ptr) \
29 (HIWORD(ptr) ? HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, (ptr) ) : 0)
30 #define SEGPTR_GET(ptr) MapLS(ptr)
32 inline static LPSTR
SEGPTR_STRDUP( LPCSTR str
)
36 INT len
= strlen(str
) + 1;
37 LPSTR p
= HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR
, len
);
38 if (p
) memcpy( p
, str
, len
);
45 /* DO NOT USE THEM!! they will go away soon */
47 inline static LPWSTR
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
52 if (!str
) return NULL
;
53 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
54 ret
= HeapAlloc( heap
, flags
, len
* sizeof(WCHAR
) );
55 if (ret
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
59 inline static LPSTR
HEAP_strdupWtoA( HANDLE heap
, DWORD flags
, LPCWSTR str
)
64 if (!str
) return NULL
;
65 len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
66 ret
= HeapAlloc( heap
, flags
, len
);
67 if(ret
) WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
71 #endif /* __WINE_HEAP_H */