Fix typo in OUTLINETEXTMETRIC definition.
[wine.git] / include / heap.h
blob0840e10c318409c007365e2442fac1e58aa3bad0
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 <string.h>
13 #include "winbase.h"
14 #include "winnls.h"
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)
35 /* strdup macros */
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 );
43 return p;
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) );
51 return p;
54 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
56 LPWSTR ret;
57 INT len;
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 );
63 return ret;
66 inline static LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
68 LPSTR ret;
69 INT len;
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 );
75 return ret;
78 #endif /* __WINE_HEAP_H */