【发布时间】:2017-06-09 15:02:16
【问题描述】:
有没有一种方法可以编译调用DriverPackagePreinstall()(使用 Pinvoke)的应用程序,即使它是针对 32 位的,它也可以在 64 位设备 (Windows 7) 上运行?
原因是它将作为更大应用程序(使用 Windows Installer 项目)的安装程序的一部分运行,该应用程序将针对 32 位,但也必须在 64 位平台上运行。
这是我的代码:
using System;
using System.Linq;
using System.Runtime.InteropServices;
namespace MyDriver
{
class Program
{
static void Main(string[] args)
{
if (args.Count() == 0)
{
Console.WriteLine("Please specify filename!");
return;
}
int result= DriverPackagePreinstall(args[0], 0);
if (result == 0)
{
Console.WriteLine("Success");
} else {
Console.WriteLine("Error: 0x{0}", result.ToString("X8"));
}
}
[DllImport("DIFxAPI.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern Int32 DriverPackagePreinstall(
[MarshalAs(UnmanagedType.LPTStr)] string DriverPackageInfPath,
Int32 Flags);
}
}
}
如果我构建此目标 x86,并尝试在 64 位机器上运行,我会收到错误 E0000235 (ERROR_IN_WOW64)。如果我构建目标 x64,此错误就会消失。
现在我不介意编译两次并让安装程序根据要安装的平台决定安装哪个。但是,如果我尝试在包含 64 位版本的情况下构建安装程序,则会出现错误,
263 File 'MyDriver.x64.exe' targeting 'AMD64' is not compatible with the project's target platform 'x86'
另一种方法是让安装程序在构建时忽略此错误(并在项目安装时运行它)会很好。
【问题讨论】:
标签: c# windows-installer pinvoke 32bit-64bit drivers