У меня проблема с вызовом / реализацией SetupVerifyInfFile .
Когда я вызываю функцию VerifyInfFile
, я получаю исключение «Параметр неверен».
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool SetupVerifyInfFile(
string FileName,
IntPtr AltPlatformInfo,
ref IntPtr InfSignerInfo);
[StructLayout(LayoutKind.Sequential)]
public struct SP_INF_SIGNER_INFO
{
public int CbSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string CatalogFile;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string DigitalSigner;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string DigitalSignerVersion;
}
public static void VerifyInfFile(string infPath)
{
SP_INF_SIGNER_INFO infSignerInfo = default;
infSignerInfo.CbSize = Marshal.SizeOf(infSignerInfo);
var infSignerPtr = Marshal.AllocHGlobal(infSignerInfo.CbSize);
try
{
Marshal.StructureToPtr(infSignerInfo, infSignerPtr, false);
if (!SetupVerifyInfFile(infPath, IntPtr.Zero, ref infSignerPtr))
throw new Exception("Error calling SetupVerifyInfFile().", new
Win32Exception(Marshal.GetLastWin32Error()));
}
finally
{
Marshal.FreeHGlobal(infSignerPtr);
}
}