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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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)
134 TRACE("(%p, %ld, %p, %ld, %p)\n", InfSpec, SearchControl, ReturnBuffer,
135 ReturnBufferSize, RequiredSize);
139 if (SearchControl == INFINFO_INF_SPEC_IS_HINF)
140 SetLastError(ERROR_INVALID_HANDLE);
142 SetLastError(ERROR_INVALID_PARAMETER);
147 if (!ReturnBuffer && ReturnBufferSize)
149 SetLastError(ERROR_INVALID_PARAMETER);
153 switch (SearchControl)
155 case INFINFO_INF_SPEC_IS_HINF:
158 case INFINFO_INF_NAME_IS_ABSOLUTE:
159 case INFINFO_DEFAULT_SEARCH:
160 inf = SetupOpenInfFileW(InfSpec, NULL,
161 INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL);
163 case INFINFO_REVERSE_DEFAULT_SEARCH:
164 inf = search_for_inf(InfSpec, SearchControl);
166 case INFINFO_INF_PATH_LIST_SEARCH:
167 FIXME("Unhandled search control: %ld\n", SearchControl);
174 SetLastError(ERROR_INVALID_PARAMETER);
178 if (inf == INVALID_HANDLE_VALUE)
180 SetLastError(ERROR_FILE_NOT_FOUND);
184 ret = fill_inf_info(inf, ReturnBuffer, ReturnBufferSize, RequiredSize);
186 if (SearchControl >= INFINFO_INF_NAME_IS_ABSOLUTE)
187 SetupCloseInfFile(inf);
192 /***********************************************************************
193 * SetupQueryInfFileInformationA (SETUPAPI.@)
195 BOOL WINAPI SetupQueryInfFileInformationA(PSP_INF_INFORMATION InfInformation,
196 UINT InfIndex, PSTR ReturnBuffer,
197 DWORD ReturnBufferSize, PDWORD RequiredSize)
203 ret = SetupQueryInfFileInformationW(InfInformation, InfIndex, NULL, 0, &size);
207 filenameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
209 ret = SetupQueryInfFileInformationW(InfInformation, InfIndex,
210 filenameW, size, &size);
213 HeapFree(GetProcessHeap(), 0, filenameW);
218 *RequiredSize = size;
222 if (ReturnBufferSize)
224 SetLastError(ERROR_INVALID_PARAMETER);
231 if (size > ReturnBufferSize)
233 SetLastError(ERROR_INSUFFICIENT_BUFFER);
237 WideCharToMultiByte(CP_ACP, 0, filenameW, -1, ReturnBuffer, size, NULL, NULL);
238 HeapFree(GetProcessHeap(), 0, filenameW);
243 /***********************************************************************
244 * SetupQueryInfFileInformationW (SETUPAPI.@)
246 BOOL WINAPI SetupQueryInfFileInformationW(PSP_INF_INFORMATION InfInformation,
247 UINT InfIndex, PWSTR ReturnBuffer,
248 DWORD ReturnBufferSize, PDWORD RequiredSize)
253 TRACE("(%p, %u, %p, %ld, %p) Stub!\n", InfInformation, InfIndex,
254 ReturnBuffer, ReturnBufferSize, RequiredSize);
258 SetLastError(ERROR_INVALID_PARAMETER);
263 FIXME("Appended INF files are not handled\n");
265 ptr = (LPWSTR)&InfInformation->VersionData[0];
269 *RequiredSize = len + 1;
274 if (ReturnBufferSize < len)
276 SetLastError(ERROR_INSUFFICIENT_BUFFER);
280 lstrcpyW(ReturnBuffer, ptr);