[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupFindFirstLine(IntPtr InfHandle, [MarshalAs(UnmanagedType.LPTStr)] string Section, [MarshalAs(UnmanagedType.LPTStr)] string Key, ref INFCONTEXT Context);
Public Declare Auto Function SetupFindFirstLine Lib "setupapi.dll" (ByVal InfHandle As IntPtr, ByVal Section As String, ByVal Key As String, ByRef Context As INFCONTEXT) As Boolean
Do you know one? Please contribute it!
Parameters
InfHandle | Handle to the INF file to query. |
Section | Pointer to a null-terminated string specifying the section of the INF files to search in. |
Key | Optional pointer to a null-terminated string specifying the key to search for within the section. The null-terminated string should not exceed the size of the destination buffer. This parameter can be NULL. If Key is NULL, the first line in the section is returned. |
Context | Pointer to a structure that receives the context information used internally by the INF handle. Applications must not overwrite values in this structure. |
Return Value
If the function could not find a line, the return value is zero. To get extended error information, call GetLastError.
If the InfHandle parameter references multiple INF files that have been appended together using SetupOpenAppendInfFile, the SetupFindFirstLine function searches across the specified section in all of the files referenced by the specified HINF.
C#
string infFile = <INF file full path>;
uint ErrorLine = 0;
IntPtr infHandle = SetupOpenInfFile(infFile, null, INF_STYLE_OLDNT | INF_STYLE_WIN4, out ErrorLine);
int iCode = Marshal.GetLastWin32Error();
if (infHandle.ToInt64() != INVALID_HANDLE_VALUE)
{
Console.WriteLine("INF file was opened successfully.");
INFCONTEXT Context = new INFCONTEXT();
if (SetupFindFirstLine(infHandle, "Manufacturer", null, ref Context) == true)
{
Console.WriteLine("Manufacturers list:");
string manufacturerName = "";
manufacturerName = manufacturerName.PadLeft(256, ' ');
Int32 requiredSize = manufacturerName.Length;
SetupGetStringField(ref Context, 1, manufacturerName, manufacturerName.Length, out requiredSize);
manufacturerName = manufacturerName.Substring(0, requiredSize-1);
Console.WriteLine(manufacturerName);
while(SetupFindNextLine(ref Context, out Context) == true)
{
manufacturerName = manufacturerName.PadLeft(256, ' ');
requiredSize = manufacturerName.Length;
SetupGetStringField(ref Context, 1, manufacturerName, manufacturerName.Length, out requiredSize);
manufacturerName = manufacturerName.Substring(0, requiredSize - 1);
Console.WriteLine(manufacturerName);
}
}
else
{
Console.WriteLine("Can't find [Manufacturer] section.");
}
SetupCloseInfFile(infHandle);
}
else
{
Console.WriteLine("Failed to open INF file. Error code - {0}.", iCode);
if (ErrorLine != 0)
{
Console.WriteLine("Failure line - {0}.", ErrorLine);
}
}
VB
Dim infFile As String = <INF file full path>
Dim ErrorLine As UInt32 = 0
Dim infHandle As IntPtr = SetupOpenInfFile(infFile, Nothing, INF_STYLE_OLDNT Or INF_STYLE_WIN4, ErrorLine)
Dim iCode As Integer = Marshal.GetLastWin32Error()
If infHandle.ToInt64() <> INVALID_HANDLE_VALUE Then
Console.WriteLine("INF file was opened successfully.")
Dim Context As INFCONTEXT = New INFCONTEXT()
If SetupFindFirstLine(infHandle, "Manufacturer", Nothing, Context) = True Then
Console.WriteLine("Manufacturers list:")
Dim manufacturerName As String = ""
manufacturerName = manufacturerName.PadLeft(256, " "c)
Dim requiredSize As Int32 = manufacturerName.Length
SetupGetStringField(Context, 1, manufacturerName, manufacturerName.Length, requiredSize)
manufacturerName = manufacturerName.Substring(0, requiredSize - 1)
Console.WriteLine(manufacturerName)
While SetupFindNextLine(Context, Context) = True
manufacturerName = manufacturerName.PadLeft(256, " "c)
requiredSize = manufacturerName.Length
SetupGetStringField(Context, 1, manufacturerName, manufacturerName.Length, requiredSize)
manufacturerName = manufacturerName.Substring(0, requiredSize - 1)
Console.WriteLine(manufacturerName)
End While
Else
Console.WriteLine("Can't find [Manufacturer] section.")
End If
SetupCloseInfFile(infHandle)
Else
Console.WriteLine("Failed to open INF file. Error code - {0}.", iCode)
If ErrorLine <> 0 Then
Console.WriteLine("Failure line - {0}.", ErrorLine)
End If
End If