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