ReactOS 0.4.15-dev-6712-g46b4b55
infsupp.c
Go to the documentation of this file.
1/*
2 * ReactOS kernel
3 * Copyright (C) 2002 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19/*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: base/setup/lib/infsupp.c
23 * PURPOSE: Interfacing with Setup* API .INF Files support functions
24 * PROGRAMMERS: Hervé Poussineau
25 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
26 */
27
28/* INCLUDES ******************************************************************/
29
30#include "usetup.h"
31
32#define NDEBUG
33#include <debug.h>
34
35/* SETUP* API COMPATIBILITY FUNCTIONS ****************************************/
36
37/* Functions from the INFLIB library */
38
39extern VOID InfCloseFile(HINF InfHandle);
40// #define SetupCloseInfFile InfCloseFile
41VOID
44 IN HINF InfHandle)
45{
46 if (InfHandle == INVALID_HANDLE_VALUE)
47 return;
48 InfCloseFile(InfHandle);
49}
50
51// #define SetupFindFirstLineW InfpFindFirstLineW
52BOOL
55 IN HINF InfHandle,
56 IN PCWSTR Section,
59{
60 PINFCONTEXT pContext;
61 BOOL ret;
62
63 if (InfHandle == INVALID_HANDLE_VALUE)
64 return FALSE;
65
66 ret = InfFindFirstLine(InfHandle, Section, Key, &pContext);
67 if (!ret)
68 return FALSE;
69
70 memcpy(Context, pContext, sizeof(INFCONTEXT));
71 InfFreeContext(pContext);
72 return TRUE;
73}
74
75extern BOOLEAN InfFindNextLine(PINFCONTEXT ContextIn,
76 PINFCONTEXT ContextOut);
77// #define SetupFindNextLine InfFindNextLine
78BOOL
81 IN PINFCONTEXT ContextIn,
82 OUT PINFCONTEXT ContextOut)
83{
84 return !!InfFindNextLine(ContextIn, ContextOut);
85}
86
88// #define SetupGetFieldCount InfGetFieldCount
93{
95}
96
97/*
98 * This function corresponds to an undocumented but exported SetupAPI function
99 * that exists since WinNT4 and is still present in Win10.
100 * The returned string pointer is a read-only pointer to a string in the
101 * maintained INF cache, and is always in UNICODE (on NT systems).
102 */
105 PWCHAR *Data);
106PCWSTR
107WINAPI
111{
112 PWCHAR Data = NULL;
114 return NULL;
115 return Data;
116}
117
120 PUCHAR ReturnBuffer,
123// #define SetupGetBinaryField InfGetBinaryField
124BOOL
125WINAPI
129 OUT PUCHAR ReturnBuffer,
132{
133 return !!InfGetBinaryField(Context,
135 ReturnBuffer,
138}
139
142 INT *IntegerValue);
143// #define SetupGetIntField InfGetIntField
144BOOL
145WINAPI
149 OUT INT *IntegerValue) // PINT
150{
151 return !!InfGetIntField(Context, FieldIndex, IntegerValue);
152}
153
156 PWSTR ReturnBuffer,
159// #define SetupGetMultiSzFieldW InfGetMultiSzField
160BOOL
161WINAPI
165 OUT PWSTR ReturnBuffer,
168{
171 ReturnBuffer,
174}
175
178 PWSTR ReturnBuffer,
181// #define SetupGetStringFieldW InfGetStringField
182BOOL
183WINAPI
187 OUT PWSTR ReturnBuffer,
190{
191 return !!InfGetStringField(Context,
193 ReturnBuffer,
196}
197
198/* SetupOpenInfFileW with support for a user-provided LCID */
199// #define SetupOpenInfFileExW InfpOpenInfFileW
200HINF
201WINAPI
204 IN PCWSTR InfClass,
205 IN DWORD InfStyle,
207 OUT PUINT ErrorLine)
208{
209 HINF hInf = NULL;
210 UNICODE_STRING FileNameU;
211 ULONG ErrorLineUL;
213
214 RtlInitUnicodeString(&FileNameU, FileName);
215 Status = InfOpenFile(&hInf,
216 &FileNameU,
218 &ErrorLineUL);
219 *ErrorLine = (UINT)ErrorLineUL;
220 if (!NT_SUCCESS(Status))
222
223 return hInf;
224}
225
226
227/* GLOBALS *******************************************************************/
228
239
240
241/* HELPER FUNCTIONS **********************************************************/
242
245 IN PSTR FileBuffer,
247 IN PCSTR InfClass,
248 IN DWORD InfStyle,
250 OUT PUINT ErrorLine)
251{
252 HINF hInf = NULL;
253 ULONG ErrorLineUL;
255
257 FileBuffer,
258 FileSize,
260 &ErrorLineUL);
261 *ErrorLine = (UINT)ErrorLineUL;
262 if (!NT_SUCCESS(Status))
264
265 return hInf;
266}
267
268/* EOF */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
HINF WINAPI INF_OpenBufferedFileA(IN PSTR FileBuffer, IN ULONG FileSize, IN PCSTR InfClass, IN DWORD InfStyle, IN LCID LocaleId, OUT PUINT ErrorLine)
Definition: infsupp.c:244
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
Status
Definition: gdiplustypes.h:25
BOOLEAN InfFindFirstLine(HINF InfHandle, PCSTR Section, PCSTR Key, PINFCONTEXT Context)
Definition: inffile.c:1050
BOOLEAN InfOpenFile(PHINF InfHandle, PCSTR FileName, PULONG ErrorLine)
Definition: inffile.c:918
VOID InfFreeContext(PINFCONTEXT Context)
Definition: infrosget.c:135
NTSTATUS InfOpenBufferedFile(PHINF InfHandle, PVOID Buffer, ULONG BufferSize, LANGID LanguageId, PULONG ErrorLine)
Definition: infrosgen.c:51
ULONG(WINAPI * pSpInfGetFieldCount)(IN PINFCONTEXT Context)
Definition: infsupp.h:85
pSpInfGetBinaryField SpInfGetBinaryField
Definition: infsupp.c:90
HINF(WINAPI * pSpInfOpenInfFile)(IN PCWSTR FileName, IN PCWSTR InfClass, IN DWORD InfStyle, IN LCID LocaleId, OUT PUINT ErrorLine)
Definition: infsupp.h:143
pSpInfGetMultiSzField SpInfGetMultiSzField
Definition: infsupp.c:92
BOOL(WINAPI * pSpInfGetStringField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.h:123
BOOL(WINAPI * pSpInfGetMultiSzField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.h:112
pSpInfGetStringField SpInfGetStringField
Definition: infsupp.c:93
BOOL(WINAPI * pSpInfFindFirstLine)(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.h:67
BOOL(WINAPI * pSpInfGetIntField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT INT *IntegerValue)
Definition: infsupp.h:103
pSpInfGetFieldCount SpInfGetFieldCount
Definition: infsupp.c:89
pSpInfFindNextLine SpInfFindNextLine
Definition: infsupp.c:88
pSpInfGetIntField SpInfGetIntField
Definition: infsupp.c:91
pSpInfFindFirstLine SpInfFindFirstLine
Definition: infsupp.c:87
VOID(WINAPI * pSpInfCloseInfFile)(IN HINF InfHandle)
Definition: infsupp.h:60
pSpInfOpenInfFile SpInfOpenInfFile
Definition: infsupp.c:95
pSpInfCloseInfFile SpInfCloseInfFile
Definition: infsupp.c:86
pSpInfGetField SpInfGetField
Definition: infsupp.c:94
PCWSTR(WINAPI * pSpInfGetField)(IN PINFCONTEXT Context, IN ULONG FieldIndex)
Definition: infsupp.h:134
BOOL(WINAPI * pSpInfGetBinaryField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PUCHAR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.h:92
BOOL(WINAPI * pSpInfFindNextLine)(IN PINFCONTEXT ContextIn, OUT PINFCONTEXT ContextOut)
Definition: infsupp.h:77
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned int * PUINT
Definition: ndis.h:50
unsigned int UINT
Definition: ndis.h:50
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
long LONG
Definition: pedump.c:60
PCWSTR WINAPI pSetupGetField(IN PINFCONTEXT Context, IN ULONG FieldIndex)
Definition: infsupp.c:108
HINF WINAPI SetupOpenInfFileExW(IN PCWSTR FileName, IN PCWSTR InfClass, IN DWORD InfStyle, IN LCID LocaleId, OUT PUINT ErrorLine)
Definition: infsupp.c:35
#define LANGIDFROMLCID(l)
Definition: nls.h:18
DWORD LCID
Definition: nls.h:13
_In_ DWORD FieldIndex
Definition: setupapi.h:1895
_In_ DWORD _In_ DWORD ReturnBufferSize
Definition: setupapi.h:1897
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG
Definition: typedefs.h:59
char * PSTR
Definition: typedefs.h:51
const uint16_t * PCWSTR
Definition: typedefs.h:57
int32_t INT
Definition: typedefs.h:58
const char * PCSTR
Definition: typedefs.h:52
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:184
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:54
BOOLEAN InfGetIntField(PINFCONTEXT Context, ULONG FieldIndex, INT *IntegerValue)
Definition: infrosget.c:85
BOOL WINAPI SetupGetMultiSzFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:162
BOOL WINAPI SetupGetIntField(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT INT *IntegerValue)
Definition: infsupp.c:146
ULONG WINAPI SetupGetFieldCount(IN PINFCONTEXT Context)
Definition: infsupp.c:91
BOOLEAN InfGetDataField(PINFCONTEXT Context, ULONG FieldIndex, PWCHAR *Data)
Definition: infrosget.c:127
VOID InfCloseFile(HINF InfHandle)
Definition: inffile.c:1028
BOOL WINAPI SetupFindNextLine(IN PINFCONTEXT ContextIn, OUT PINFCONTEXT ContextOut)
Definition: infsupp.c:80
BOOLEAN InfFindNextLine(PINFCONTEXT ContextIn, PINFCONTEXT ContextOut)
Definition: inffile.c:1107
BOOLEAN InfGetBinaryField(PINFCONTEXT Context, ULONG FieldIndex, PUCHAR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
Definition: inffile.c:1260
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
LONG InfGetFieldCount(PINFCONTEXT Context)
Definition: inffile.c:1250
BOOLEAN InfGetMultiSzField(PINFCONTEXT Context, ULONG FieldIndex, PWSTR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
Definition: infrosget.c:94
BOOL WINAPI SetupGetBinaryField(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PUCHAR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:126
BOOLEAN InfGetStringField(PINFCONTEXT Context, ULONG FieldIndex, PWSTR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
Definition: infrosget.c:106
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID _Out_ PULONG RequiredSize
Definition: wdfdevice.h:4439
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING _In_ PCUNICODE_STRING _In_ LCID LocaleId
Definition: wdfpdo.h:437
#define WINAPI
Definition: msvc.h:6