2 * setupapi query functions
4 * Copyright 2006 James Hawkins
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/debug.h"
32 #include "setupapi_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
36 /* fills the PSP_INF_INFORMATION struct fill_info is TRUE
37 * always returns the required size of the information
39 static BOOL fill_inf_info(HINF inf, PSP_INF_INFORMATION buffer, DWORD size, DWORD *required)
41 LPCWSTR filename = PARSER_get_inf_filename(inf);
42 DWORD total_size = FIELD_OFFSET(SP_INF_INFORMATION, VersionData)
43 + (lstrlenW(filename) + 1) * sizeof(WCHAR);
45 if (required) *required = total_size;
47 /* FIXME: we need to parse the INF file to find the correct version info */
50 if (size < total_size)
52 SetLastError(ERROR_INSUFFICIENT_BUFFER);
55 buffer->InfStyle = INF_STYLE_WIN4;
57 /* put the filename in buffer->VersionData */
58 lstrcpyW((LPWSTR)&buffer->VersionData[0], filename);
63 static HINF search_for_inf(LPCVOID InfSpec, DWORD SearchControl)
65 HINF hInf = INVALID_HANDLE_VALUE;
66 WCHAR inf_path[MAX_PATH];
68 static const WCHAR infW[] = {'\\','i','n','f','\\',0};
69 static const WCHAR system32W[] = {'\\','s','y','s','t','e','m','3','2','\\',0};
71 if (SearchControl == INFINFO_REVERSE_DEFAULT_SEARCH)
73 GetWindowsDirectoryW(inf_path, MAX_PATH);
74 lstrcatW(inf_path, system32W);
75 lstrcatW(inf_path, InfSpec);
77 hInf = SetupOpenInfFileW(inf_path, NULL,
78 INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL);
79 if (hInf != INVALID_HANDLE_VALUE)
82 GetWindowsDirectoryW(inf_path, MAX_PATH);
83 lstrcpyW(inf_path, infW);
84 lstrcatW(inf_path, InfSpec);
86 return SetupOpenInfFileW(inf_path, NULL,
87 INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL);
90 return INVALID_HANDLE_VALUE;
93 /***********************************************************************
94 * SetupGetInfInformationA (SETUPAPI.@)
97 BOOL WINAPI SetupGetInfInformationA(LPCVOID InfSpec, DWORD SearchControl,
98 PSP_INF_INFORMATION ReturnBuffer,
99 DWORD ReturnBufferSize, PDWORD RequiredSize)
101 LPWSTR inf = (LPWSTR)InfSpec;
105 if (InfSpec && SearchControl >= INFINFO_INF_NAME_IS_ABSOLUTE)
107 len = lstrlenA(InfSpec) + 1;
108 inf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
109 MultiByteToWideChar(CP_ACP, 0, InfSpec, -1, inf, len);
112 ret = SetupGetInfInformationW(inf, SearchControl, ReturnBuffer,
113 ReturnBufferSize, RequiredSize);
115 if (SearchControl >= INFINFO_INF_NAME_IS_ABSOLUTE)
116 HeapFree(GetProcessHeap(), 0, inf);
121 /***********************************************************************
122 * SetupGetInfInformationW (SETUPAPI.@)
125 * Only handles the case when InfSpec is an INF handle.
127 BOOL WINAPI SetupGetInfInformationW(LPCVOID InfSpec, DWORD SearchControl,
128 PSP_INF_INFORMATION ReturnBuffer,
129 DWORD ReturnBufferSize, PDWORD RequiredSize)
135 TRACE("(%p, %d, %p, %d, %p)\n", InfSpec, SearchControl, ReturnBuffer,
136 ReturnBufferSize, RequiredSize);
140 if (SearchControl == INFINFO_INF_SPEC_IS_HINF)
141 SetLastError(ERROR_INVALID_HANDLE);
143 SetLastError(ERROR_INVALID_PARAMETER);
148 switch (SearchControl)
150 case INFINFO_INF_SPEC_IS_HINF:
153 case INFINFO_INF_NAME_IS_ABSOLUTE:
154 case INFINFO_DEFAULT_SEARCH:
155 inf = SetupOpenInfFileW(InfSpec, NULL,
156 INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL);
158 case INFINFO_REVERSE_DEFAULT_SEARCH:
159 inf = search_for_inf(InfSpec, SearchControl);
161 case INFINFO_INF_PATH_LIST_SEARCH:
162 FIXME("Unhandled search control: %d\n", SearchControl);
169 SetLastError(ERROR_INVALID_PARAMETER);
173 if (inf == INVALID_HANDLE_VALUE)
175 SetLastError(ERROR_FILE_NOT_FOUND);
179 ret = fill_inf_info(inf, ReturnBuffer, ReturnBufferSize, &infSize);
180 if (!ReturnBuffer && (ReturnBufferSize >= infSize))
182 SetLastError(ERROR_INVALID_PARAMETER);
185 if (RequiredSize) *RequiredSize = infSize;
187 if (SearchControl >= INFINFO_INF_NAME_IS_ABSOLUTE)
188 SetupCloseInfFile(inf);
193 /***********************************************************************
194 * SetupQueryInfFileInformationA (SETUPAPI.@)
196 BOOL WINAPI SetupQueryInfFileInformationA(PSP_INF_INFORMATION InfInformation,
197 UINT InfIndex, PSTR ReturnBuffer,
198 DWORD ReturnBufferSize, PDWORD RequiredSize)
204 ret = SetupQueryInfFileInformationW(InfInformation, InfIndex, NULL, 0, &size);
208 filenameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
210 ret = SetupQueryInfFileInformationW(InfInformation, InfIndex,
211 filenameW, size, &size);
214 HeapFree(GetProcessHeap(), 0, filenameW);
219 *RequiredSize = size;
223 if (ReturnBufferSize)
225 SetLastError(ERROR_INVALID_PARAMETER);
232 if (size > ReturnBufferSize)
234 SetLastError(ERROR_INSUFFICIENT_BUFFER);
238 WideCharToMultiByte(CP_ACP, 0, filenameW, -1, ReturnBuffer, size, NULL, NULL);
239 HeapFree(GetProcessHeap(), 0, filenameW);
244 /***********************************************************************
245 * SetupQueryInfFileInformationW (SETUPAPI.@)
247 BOOL WINAPI SetupQueryInfFileInformationW(PSP_INF_INFORMATION InfInformation,
248 UINT InfIndex, PWSTR ReturnBuffer,
249 DWORD ReturnBufferSize, PDWORD RequiredSize)
254 TRACE("(%p, %u, %p, %d, %p) Stub!\n", InfInformation, InfIndex,
255 ReturnBuffer, ReturnBufferSize, RequiredSize);
259 SetLastError(ERROR_INVALID_PARAMETER);
264 FIXME("Appended INF files are not handled\n");
266 ptr = (LPWSTR)&InfInformation->VersionData[0];
270 *RequiredSize = len + 1;
275 if (ReturnBufferSize < len)
277 SetLastError(ERROR_INSUFFICIENT_BUFFER);
281 lstrcpyW(ReturnBuffer, ptr);