Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than setupapi, prefix the name with the module name and a period.
The 1-based index of the field within the specified line from which the string should be retrieved. Use a FieldIndex of 0 to retrieve a string key, if present.
Optional pointer to a buffer that receives the null-terminated string. You should ensure the destination buffer is the same size or larger than the source buffer. This parameter can be NULL. See the Remarks section.
Optional pointer to a variable that receives the required size for the buffer pointed to by the ReturnBuffer parameter, in characters. If ReturnBuffer is specified and the actual size needed is larger than the value specified by ReturnBufferSize, the function fails and does not store the string in the buffer. In this case, a call to GetLastError returns ERROR_INSUFFICIENT_BUFFER. For the Unicode version of this function, the required size is in characters. This includes the null terminator.
Return Value
If the function succeeds, the return value is a nonzero value.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Tips & Tricks:
None.
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:");
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);
}
}
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).