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(str) \
27 (HIWORD(str) ? HEAP_strdupA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
28 #define SEGPTR_STRDUP_WtoA(str) \
29 (HIWORD(str) ? HEAP_strdupWtoA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
30 #define SEGPTR_FREE(ptr) \
31 (HIWORD(ptr) ? HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, (ptr) ) : 0)
32 #define SEGPTR_GET(ptr) MapLS(ptr)
36 /* DO NOT USE THEM!! they will go away soon */
38 inline static LPSTR
HEAP_strdupA( HANDLE heap
, DWORD flags
, LPCSTR str
)
40 INT len
= strlen(str
) + 1;
41 LPSTR p
= HeapAlloc( heap
, flags
, len
);
42 if (p
) memcpy( p
, str
, len
);
46 inline static LPWSTR
HEAP_strdupW( HANDLE heap
, DWORD flags
, LPCWSTR str
)
48 INT len
= strlenW(str
) + 1;
49 LPWSTR p
= HeapAlloc( heap
, flags
, len
* sizeof(WCHAR
) );
50 if (p
) memcpy( p
, str
, len
* sizeof(WCHAR
) );
54 inline static LPWSTR
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
59 if (!str
) return NULL
;
60 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
61 ret
= HeapAlloc( heap
, flags
, len
* sizeof(WCHAR
) );
62 if (ret
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
66 inline static LPSTR
HEAP_strdupWtoA( HANDLE heap
, DWORD flags
, LPCWSTR str
)
71 if (!str
) return NULL
;
72 len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
73 ret
= HeapAlloc( heap
, flags
, len
);
74 if(ret
) WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
78 #endif /* __WINE_HEAP_H */