More verbose error messages when application load fails.
[wine.git] / include / heap.h
blob84ed5fd056ac5378c8ca45f0ac2f53fbb5b0330d
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 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)
38 /* strdup macros */
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 );
46 return p;
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) );
54 return p;
57 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
59 LPWSTR ret;
60 INT len;
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 );
66 return ret;
69 inline static LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
71 LPSTR ret;
72 INT len;
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 );
78 return ret;
81 /* system heap private data */
82 /* you must lock the system heap before using this structure */
83 typedef struct
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 */
91 } SYSTEM_HEAP_DESCR;
93 extern SYSTEM_HEAP_DESCR *SystemHeapDescr;
95 #endif /* __WINE_HEAP_H */