解析INF文件中支持的设备硬件ID
2021-11-19
299
0
安装Windows驱动,首先得知道INF支持的硬件ID.本人手中有一个测试的inf文件,其内容如下:
设备支持的硬件ID如下:
字符串内容如下:
编写一个程序,用来解析INF文件。
#include <iostream>
#include <windows.h>
#include <SetupAPI.h>
#pragma comment(lib,"setupapi.lib")
int main()
{
HINF hInf = SetupOpenInfFile("d:\\TEST.inf", NULL, INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL);
if (INVALID_HANDLE_VALUE == hInf)
{
return 0;
}
const char* szSection = NULL;
INFCONTEXT infContext1, infContext2;
TCHAR szSrcFile[MAX_PATH];
ZeroMemory(szSrcFile, MAX_PATH);
szSection = "Standard.NTamd64";//这个是节名
char szValueData[512] = { 0 };
BOOL bWorking = SetupFindFirstLine(hInf, szSection, NULL, &infContext1);
while (bWorking)
{
// Get the xxx.CopyFile section
if (!SetupGetStringField(&infContext1, 0, szValueData, MAX_PATH, NULL))
{
bWorking = SetupFindNextLine(&infContext1, &infContext2);
infContext1 = infContext2;
continue;
}
int count = SetupGetFieldCount(&infContext1);
for (int i = 0; i <= count; i++)
{
char buff[512] = { 0 };
ULONG rtn = 0;
SetupGetStringField(&infContext1, i, buff, 512, &rtn);
printf("%s\n", buff);
}
bWorking = SetupFindNextLine(&infContext1, &infContext2);
infContext1 = infContext2;
printf("\n");
}
SetupCloseInfFile(hInf);
return 0;
}
运行结果如下:
参考代码如下:http://blog.sina.com.cn/s/blog_5a237c2b0100samh.html