Add CF_UNICODETEXT as primary text clipboard format.
[wine.git] / include / heap.h
blob625d5863decb6fc70580787e573a0317441dbc7f
1 /*
2 * Win32 heap definitions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #ifndef __WINE_HEAP_H
8 #define __WINE_HEAP_H
10 #include "config.h"
12 #include "winbase.h"
13 #include "winnls.h"
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)
37 /* strdup macros */
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 );
45 return p;
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) );
53 return p;
56 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
58 LPWSTR ret;
59 INT len;
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 );
65 return ret;
68 inline static LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
70 LPSTR ret;
71 INT len;
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 );
77 return ret;
80 /* system heap private data */
81 /* you must lock the system heap before using this structure */
82 typedef struct
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 */
90 } SYSTEM_HEAP_DESCR;
92 extern SYSTEM_HEAP_DESCR *SystemHeapDescr;
94 #endif /* __WINE_HEAP_H */