2011-04-12 20 views
1

我试图预装一个.inf驱动程序后我的Windows程序加载并使用this question作为示例。我在VB.Net编写,而原来的问题是在C#这样做它可能是我迷失东京但这里是我有:错误使用Windows驱动程序工具包DriverPackagePreinstall

Public Shared Function PreInstall(ByVal fileName As String, Optional ByVal useDefaultLocation As Boolean = True) As Boolean 
     Try 
      Dim file As String = IIf(useDefaultLocation, DriverLocation(fileName), fileName) 
      Dim result As Int32 = DriverPackagePreinstall(file, 0) 'this is not working but I don't know why?!? 
      Return (result = ERROR_SUCCESS OrElse result = ERROR_ALREADY_EXISTS) 
     Catch ex As Exception 
      My.Application.LogError(ex, New StringPair("Driver", fileName)) 
     End Try 
     Return False 
    End Function 

    Private Shared ReadOnly Property DriverLocation(ByVal fileName As String) As String 
     Get 
      Return String.Format("{0}\Drivers\{1}", ApplicationDirectory(), fileName) 
     End Get 
    End Property 

    Public Function ApplicationDirectory() As String 
     If My.Application.IsNetworkDeployed Then 
      Return My.Application.Deployment.DataDirectory 
     Else 
      Return Application.StartupPath 
     End If 
    End Function 

    <DllImport("DIFXApi.dll", CharSet:=CharSet.Unicode)> _ 
    Public Shared Function DriverPackagePreinstall(ByVal DriverPackageInfPath As String, ByVal Flags As Int32) As Int32 
    End Function 

    Const ERROR_SUCCESS As Int32 = 0 
    Const ERROR_ALREADY_EXISTS As Int32 = &HB7 
    Const ERROR_ACCESS_DENIED As Int32 = &H5 

我的.inf文件是在一个目录中称为驱动程序和安装程序是在应用程序文件中作为所需的“数据文件”。我的应用程序通过ClickOnce部署;但是,我目前无法在当地的工厂上使用它。

但是当我使用调试器并调用PreInstall函数内部的DriverPackagePreinstall时,我得到了-536870347作为Int32结果。我知道这是没有意义的,因为它应该是一个正面的错误代码或0(ERROR_SUCCESS)。我已经检查.inf文件位于我期望的位置,并且我已经运行DIFxCmd.exe \ p,并且使用该文件位置与WDK构建环境并获得预期结果。有谁知道我为什么会在我的应用程序中得到这样一个奇怪的结果?还是有没有人有另一种/更好的方式安装一个ClickOnce应用程序的.inf驱动程序?

回答

3

如果你翻译-536870347诅咒你0xe0000235 - 一个快速搜索发现,这是在setupapi.h定义为ERROR_IN_WOW64explanation是:

如果功能32位返回ERROR_IN_WOW64 应用程序,应用程序是 在64位系统上执行,这是不允许的 。

+0

这很有道理。有没有更好的方法来确保我得到的十六进制值,而不是使用Int32作为返回类型? – TKTS 2011-04-14 15:45:12

+1

在调试器中,您可以右键单击该值并选择“十六进制显示”以查看十六进制值。如果使用string.format打印,则可以使用'{0:X}' – John 2011-04-14 22:43:06

+0

啊,再次感谢! – TKTS 2011-04-18 14:10:02

相关问题