2 * Win32 heap definitions
4 * Copyright 1996 Alexandre Julliard
15 #include "wine/unicode.h"
16 #include "wine/windef16.h" /* for SEGPTR */
18 extern HANDLE SystemHeap;
20 extern SEGPTR HEAP_GetSegptr( HANDLE heap, DWORD flags, LPCVOID ptr );
21 extern BOOL HEAP_CreateSystemHeap(void);
23 /* SEGPTR helper macros */
25 #define SEGPTR_ALLOC(size) \
26 (HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, (size) ))
27 #define SEGPTR_NEW(type) \
28 ((type *)HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, sizeof(type) ))
29 #define SEGPTR_STRDUP(str) \
30 (HIWORD(str) ? HEAP_strdupA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
31 #define SEGPTR_STRDUP_WtoA(str) \
32 (HIWORD(str) ? HEAP_strdupWtoA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
33 #define SEGPTR_FREE(ptr) \
34 (HIWORD(ptr) ? HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, (ptr) ) : 0)
35 #define SEGPTR_GET(ptr) MapLS(ptr)
39 /* DO NOT USE THEM!! they will go away soon */
41 inline static LPSTR HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
43 INT len = strlen(str) + 1;
44 LPSTR p = HeapAlloc( heap, flags, len );
45 if (p) memcpy( p, str, len );
49 inline static LPWSTR HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
51 INT len = strlenW(str) + 1;
52 LPWSTR p = HeapAlloc( heap, flags, len * sizeof(WCHAR) );
53 if (p) memcpy( p, str, len * sizeof(WCHAR) );
57 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
62 if (!str) return NULL;
63 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
64 ret = HeapAlloc( heap, flags, len * sizeof(WCHAR) );
65 if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
69 inline static LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
74 if (!str) return NULL;
75 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
76 ret = HeapAlloc( heap, flags, len );
77 if(ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
81 /* system heap private data */
82 /* you must lock the system heap before using this structure */
85 void *gdi; /* GDI heap */
86 void *user; /* USER handle table */
87 void *cursor; /* cursor information */
88 void *queue; /* message queues descriptor */
89 void *win; /* windows descriptor */
90 void *root; /* X11 root window */
93 extern SYSTEM_HEAP_DESCR *SystemHeapDescr;
95 #endif /* __WINE_HEAP_H */