2 * Setupapi miscellaneous functions
4 * Copyright 2005 Eric Kohl
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/unicode.h"
33 /**************************************************************************
36 * Frees an allocated memory block from the process heap.
39 * lpMem [I] pointer to memory block which will be freed
45 VOID WINAPI
MyFree(LPVOID lpMem
)
47 HeapFree(GetProcessHeap(), 0, lpMem
);
51 /**************************************************************************
52 * MyMalloc [SETUPAPI.@]
54 * Allocates memory block from the process heap.
57 * dwSize [I] size of the allocated memory block
60 * Success: pointer to allocated memory block
64 LPVOID WINAPI
MyMalloc(DWORD dwSize
)
66 return HeapAlloc(GetProcessHeap(), 0, dwSize
);
70 /**************************************************************************
71 * MyRealloc [SETUPAPI.@]
73 * Changes the size of an allocated memory block or allocates a memory
74 * block from the process heap.
77 * lpSrc [I] pointer to memory block which will be resized
78 * dwSize [I] new size of the memory block
81 * Success: pointer to the resized memory block
85 * If lpSrc is a NULL-pointer, then MyRealloc allocates a memory
86 * block like MyMalloc.
89 LPVOID WINAPI
MyRealloc(LPVOID lpSrc
, DWORD dwSize
)
92 return HeapAlloc(GetProcessHeap(), 0, dwSize
);
94 return HeapReAlloc(GetProcessHeap(), 0, lpSrc
, dwSize
);
98 /**************************************************************************
99 * DuplicateString [SETUPAPI.@]
101 * Duplicates a unicode string.
104 * lpSrc [I] pointer to the unicode string that will be duplicated
107 * Success: pointer to the duplicated unicode string
111 * Call MyFree() to release the duplicated string.
114 LPWSTR WINAPI
DuplicateString(LPCWSTR lpSrc
)
118 lpDst
= MyMalloc((lstrlenW(lpSrc
) + 1) * sizeof(WCHAR
));
122 strcpyW(lpDst
, lpSrc
);
128 /**************************************************************************
129 * QueryRegistryValue [SETUPAPI.@]
131 * Retrieves value data from the registry and allocates memory for the
135 * hKey [I] Handle of the key to query
136 * lpValueName [I] Name of value under hkey to query
137 * lpData [O] Destination for the values contents,
138 * lpType [O] Destination for the value type
139 * lpcbData [O] Destination for the size of data
142 * Success: ERROR_SUCCESS
146 * Use MyFree to release the lpData buffer.
149 LONG WINAPI
QueryRegistryValue(HKEY hKey
,
157 /* Get required buffer size */
159 lError
= RegQueryValueExW(hKey
, lpValueName
, 0, lpType
, NULL
, lpcbData
);
160 if (lError
!= ERROR_SUCCESS
)
163 /* Allocate buffer */
164 *lpData
= MyMalloc(*lpcbData
);
166 return ERROR_NOT_ENOUGH_MEMORY
;
168 /* Query registry value */
169 lError
= RegQueryValueExW(hKey
, lpValueName
, 0, lpType
, *lpData
, lpcbData
);
170 if (lError
!= ERROR_SUCCESS
)