[WIN32DLLS]
[reactos.git] / reactos / dll / win32 / dnsapi / dnsapi / precomp.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS System Libraries
4 * FILE: lib/dnsapi/precomp.h
5 * PURPOSE: Win32 DNS API Libary Header
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 */
8
9 #ifndef _DNSAPI_H
10 #define _DNSAPI_H
11
12 /* INCLUDES ******************************************************************/
13
14 #include <stdarg.h>
15
16 /* PSDK/NDK Headers */
17 #define WIN32_NO_STATUS
18 #define _INC_WINDOWS
19 #define COM_NO_WINDOWS_H
20 #include <windef.h>
21 #include <winbase.h>
22 #include <winnls.h>
23 #include <windns.h>
24 #define NTOS_MODE_USER
25 #include <ndk/rtlfuncs.h>
26
27 /* Internal DNSAPI Headers */
28 #include <internal/windns.h>
29
30 static inline LPWSTR dns_strdup_uw( const char *str )
31 {
32 LPWSTR ret = NULL;
33 if (str)
34 {
35 DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
36 if ((ret = HeapAlloc(GetProcessHeap(),0,( len * sizeof(WCHAR) ))))
37 MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
38 }
39 return ret;
40 }
41
42 static inline LPWSTR dns_strdup_aw( LPCSTR str )
43 {
44 LPWSTR ret = NULL;
45 if (str)
46 {
47 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
48 if ((ret = HeapAlloc(GetProcessHeap(), 0, ( len * sizeof(WCHAR) ))))
49 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
50 }
51 return ret;
52 }
53
54 static inline LPSTR dns_strdup_a( LPCSTR src )
55 {
56 LPSTR dst;
57
58 if (!src) return NULL;
59 dst = HeapAlloc(GetProcessHeap(), 0, (lstrlenA( src ) + 1) * sizeof(char) );
60 if (dst) lstrcpyA( dst, src );
61 return dst;
62 }
63
64 static inline char *dns_strdup_u( const char *src )
65 {
66 char *dst;
67
68 if (!src) return NULL;
69 dst = HeapAlloc(GetProcessHeap(), 0, (strlen( src ) + 1) * sizeof(char) );
70 if (dst) strcpy( dst, src );
71 return dst;
72 }
73
74 static inline LPWSTR dns_strdup_w( LPCWSTR src )
75 {
76 LPWSTR dst;
77
78 if (!src) return NULL;
79 dst = HeapAlloc(GetProcessHeap(), 0, (lstrlenW( src ) + 1) * sizeof(WCHAR) );
80 if (dst) lstrcpyW( dst, src );
81 return dst;
82 }
83
84 static inline LPSTR dns_strdup_wa( LPCWSTR str )
85 {
86 LPSTR ret = NULL;
87 if (str)
88 {
89 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
90 if ((ret = HeapAlloc(GetProcessHeap(), 0, len )))
91 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
92 }
93 return ret;
94 }
95
96 static inline char *dns_strdup_wu( LPCWSTR str )
97 {
98 LPSTR ret = NULL;
99 if (str)
100 {
101 DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
102 if ((ret = HeapAlloc(GetProcessHeap(), 0, len )))
103 WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
104 }
105 return ret;
106 }
107
108 static inline char *dns_strdup_au( LPCSTR src )
109 {
110 char *dst = NULL;
111 LPWSTR ret = dns_strdup_aw( src );
112
113 if (ret)
114 {
115 dst = dns_strdup_wu( ret );
116 HeapFree( GetProcessHeap(), 0, ret );
117 }
118 return dst;
119 }
120
121 static inline LPSTR dns_strdup_ua( const char *src )
122 {
123 LPSTR dst = NULL;
124 LPWSTR ret = dns_strdup_uw( src );
125
126 if (ret)
127 {
128 dst = dns_strdup_wa( ret );
129 HeapFree( GetProcessHeap(), 0, ret );
130 }
131 return dst;
132 }
133
134 #endif /* _DNSAPI_H */