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 /***********************************************************************
64 * SetupGetInfInformationA (SETUPAPI.@)
67 * If SearchControl is anything other than INFINFO_INF_SPEC_IS_HINF,
68 * then InfSpec needs to be converted to unicode.
70 BOOL WINAPI SetupGetInfInformationA(LPCVOID InfSpec, DWORD SearchControl,
71 PSP_INF_INFORMATION ReturnBuffer,
72 DWORD ReturnBufferSize, PDWORD RequiredSize)
74 return SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer,
75 ReturnBufferSize, RequiredSize);
78 /***********************************************************************
79 * SetupGetInfInformationW (SETUPAPI.@)
82 * Only handles the case when InfSpec is an INF handle.
84 BOOL WINAPI SetupGetInfInformationW(LPCVOID InfSpec, DWORD SearchControl,
85 PSP_INF_INFORMATION ReturnBuffer,
86 DWORD ReturnBufferSize, PDWORD RequiredSize)
88 HINF inf = (HINF)InfSpec;
90 TRACE("(%p, %ld, %p, %ld, %p)\n", InfSpec, SearchControl, ReturnBuffer,
91 ReturnBufferSize, RequiredSize);
95 if (SearchControl == INFINFO_INF_SPEC_IS_HINF)
96 SetLastError(ERROR_INVALID_HANDLE);
98 SetLastError(ERROR_INVALID_PARAMETER);
103 if (inf == INVALID_HANDLE_VALUE)
105 SetLastError(ERROR_FILE_NOT_FOUND);
109 if (SearchControl < INFINFO_INF_SPEC_IS_HINF ||
110 SearchControl > INFINFO_INF_PATH_LIST_SEARCH)
112 SetLastError(ERROR_INVALID_PARAMETER);
116 if (SearchControl != INFINFO_INF_SPEC_IS_HINF)
118 FIXME("Unhandled search control: %ld\n", SearchControl);
126 return fill_inf_info(inf, ReturnBuffer, ReturnBufferSize, RequiredSize);
129 /***********************************************************************
130 * SetupQueryInfFileInformationA (SETUPAPI.@)
132 BOOL WINAPI SetupQueryInfFileInformationA(PSP_INF_INFORMATION InfInformation,
133 UINT InfIndex, PSTR ReturnBuffer,
134 DWORD ReturnBufferSize, PDWORD RequiredSize)
140 ret = SetupQueryInfFileInformationW(InfInformation, InfIndex, NULL, 0, &size);
144 filenameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
146 ret = SetupQueryInfFileInformationW(InfInformation, InfIndex,
147 filenameW, size, &size);
150 HeapFree(GetProcessHeap(), 0, filenameW);
155 *RequiredSize = size;
160 if (size > ReturnBufferSize)
162 SetLastError(ERROR_INSUFFICIENT_BUFFER);
166 WideCharToMultiByte(CP_ACP, 0, filenameW, -1, ReturnBuffer, size, NULL, NULL);
167 HeapFree(GetProcessHeap(), 0, filenameW);
172 /***********************************************************************
173 * SetupQueryInfFileInformationW (SETUPAPI.@)
175 BOOL WINAPI SetupQueryInfFileInformationW(PSP_INF_INFORMATION InfInformation,
176 UINT InfIndex, PWSTR ReturnBuffer,
177 DWORD ReturnBufferSize, PDWORD RequiredSize)
182 TRACE("(%p, %u, %p, %ld, %p) Stub!\n", InfInformation, InfIndex,
183 ReturnBuffer, ReturnBufferSize, RequiredSize);
187 SetLastError(ERROR_INVALID_PARAMETER);
192 FIXME("Appended INF files are not handled\n");
194 ptr = (LPWSTR)&InfInformation->VersionData[0];
198 *RequiredSize = len + 1;
203 if (ReturnBufferSize < len)
205 SetLastError(ERROR_INSUFFICIENT_BUFFER);
209 lstrcpyW(ReturnBuffer, ptr);