Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SetupFindNextMatchLine (setupapi)
 
.
Summary

C# Signature:

[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupFindNextMatchLine(ref INFCONTEXT ContextIn, [MarshalAs(UnmanagedType.LPTStr)] string Key, out INFCONTEXT ContextOut);

VB Signature:

Public Declare Auto Function SetupFindNextMatchLine Lib "setupapi.dll" (ByRef ContextIn As INFCONTEXT, ByVal Key As String, ByRef ContextOut As INFCONTEXT) As Boolean
Declare Function SetupFindNextMatchLine Lib "setupapi.dll" (TODO) As TODO

User-Defined Types:

INFCONTEXT

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Parameters

ContextIn Pointer to the INF file context retrieved by a call to the SetupFindFirstLine function.
Key If this optional parameter is specified, it supplies a key to match. This parameter should be a null-terminated string. This parameter can be Null. If Key is not specified, the SetupFindNextMatchLine function is equivalent to the SetupFindNextLine function.
ContextOut Pointer to a variable in which this function returns the context of the found line. ContextOut can point to ContextIn if the caller wishes.

None.

Return Value

The function returns a nonzero value if it finds a matching line. Otherwise, the return value is zero. To get extended error information, call GetLastError.

Tips & Tricks:

If ContextIn.Inf references multiple INF files that have been appended together using SetupOpenAppendInfFile, the SetupFindNextMatchLine function searches across the specified section in all files referenced by the HINF to locate the next matching line.

None.

Sample Code:

Sample Code:

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 (which match the specific key):");
        string manufacturerName = "";
        manufacturerName = manufacturerName.PadLeft(256, ' ');
        Int32 requiredSize = manufacturerName.Length;
        while(SetupFindNextMatchLine(ref Context, <key to search>, 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 (which match the specific key):")
        Console.WriteLine("Manufacturers list:")
        Dim manufacturerName As String = ""
        manufacturerName = manufacturerName.PadLeft(256, " "c)
        Dim requiredSize As Int32 = manufacturerName.Length
        While SetupFindNextMatchLine(Context, <key to search>, Context) = True
            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

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions