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