Add INVALID_ATOM and MAXINTATOM to winbase.h.
[wine] / include / heap.h
1 /*
2  * Win32 heap definitions
3  *
4  * Copyright 1996 Alexandre Julliard
5  */
6
7 #ifndef __WINE_HEAP_H
8 #define __WINE_HEAP_H
9
10 #include "config.h"
11
12 #include <string.h>
13 #include "winbase.h"
14 #include "winnls.h"
15 #include "wine/unicode.h"
16 #include "wine/windef16.h"  /* for SEGPTR */
17
18 extern SEGPTR HEAP_GetSegptr( HANDLE heap, DWORD flags, LPCVOID ptr );
19
20 /* SEGPTR helper macros */
21
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_WtoA(str) \
27      (HIWORD(str) ? HEAP_strdupWtoA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
28 #define SEGPTR_FREE(ptr) \
29      (HIWORD(ptr) ? HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, (ptr) ) : 0)
30 #define SEGPTR_GET(ptr) MapLS(ptr)
31
32 inline static LPSTR SEGPTR_STRDUP( LPCSTR str )
33 {
34     if (HIWORD(str))
35     {
36         INT len = strlen(str) + 1;
37         LPSTR p = HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, len );
38         if (p) memcpy( p, str, len );
39         return p;
40     }
41     return (LPSTR)str;
42 }
43
44 /* strdup macros */
45 /* DO NOT USE THEM!!  they will go away soon */
46
47 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
48 {
49     LPWSTR ret;
50     INT len;
51
52     if (!str) return NULL;
53     len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
54     ret = HeapAlloc( heap, flags, len * sizeof(WCHAR) );
55     if (ret) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
56     return ret;
57 }
58
59 inline static LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
60 {
61     LPSTR ret;
62     INT len;
63
64     if (!str) return NULL;
65     len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
66     ret = HeapAlloc( heap, flags, len );
67     if(ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
68     return ret;
69 }
70
71 #endif  /* __WINE_HEAP_H */