Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DriverPackagePreinstall可在64位上工作(编译为32位)_C#_Windows Installer_Pinvoke_32bit 64bit_Drivers - Fatal编程技术网

C# DriverPackagePreinstall可在64位上工作(编译为32位)

C# DriverPackagePreinstall可在64位上工作(编译为32位),c#,windows-installer,pinvoke,32bit-64bit,drivers,C#,Windows Installer,Pinvoke,32bit 64bit,Drivers,有没有一种方法可以编译一个调用DriverPackagePreinstall()(使用Pinvoke)的应用程序,使它能够在64位设备(Windows 7)上工作,即使它的目标是32位 原因是它将作为更大应用程序(使用Windows installer项目)的安装程序的一部分运行,该应用程序将以32位为目标,但也必须在64位平台上运行 这是我的密码: using System; using System.Linq; using System.Runtime.InteropServices; n

有没有一种方法可以编译一个调用
DriverPackagePreinstall()
(使用Pinvoke)的应用程序,使它能够在64位设备(Windows 7)上工作,即使它的目标是32位

原因是它将作为更大应用程序(使用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位计算机上运行,则会出现错误
e000235
error\u IN_WOW64
)。如果我以x64为目标构建,这个错误就会消失

现在,我不介意编译它两次,让安装程序根据安装到的平台决定安装哪个。但是,如果我尝试在包含64位版本的同时构建安装程序,则会出现错误

以“AMD64”为目标的263文件“MyDriver.x64.exe”与项目的目标平台“x86”不兼容。


另一种方法是让安装程序在构建时忽略此错误(并在项目安装时运行此错误)。

我通过将64位和32位版本的应用程序添加到一个自解压zip文件以及一个批处理文件(决定执行哪个文件)来解决此问题

自提取器是32位exe,因此只要没有人告诉VisualStudio它包含64位exe,它就可以工作