使用 Windows 驱动程序工具包 DriverPackagePreinstall 时出错

发布于 2024-10-31 19:54:15 字数 2015 浏览 5 评论 0原文

我正在尝试在 Windows 程序加载并使用 这个问题为例。我正在用 VB.Net 编写,而最初的问题是用 C# 完成的,所以这可能是我在翻译中丢失的东西,但这就是我所拥有的:

    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 文件位于名为 Drivers 的目录中,并根据需要在应用程序文件中设置“数据文件”。我的应用程序是通过 ClickOnce 部署的;但是,我目前无法让它在我的本地机器上运行。

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

I am trying to preinstall an .inf driver after my windows program loads and was using this question as an example. I am writing in VB.Net while the original question was done in C# so it might be something I lost in translation but here's what I have:

    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

My .inf file is in a directory called Drivers and is setup in the Application Files as a required "Data File". My application is deployed via ClickOnce; however, I currently cannot get it to work on my local machince.

But when I step through with the debugger and call the DriverPackagePreinstall inside of PreInstall function, I get -536870347 as the Int32 result. I know that doesn't make sense because it should be a positive Error code or 0 (ERROR_SUCCESS). I have checked that the .inf file is in the location that I expect which it is and I have run DIFxCmd.exe \p using that file location with the WDK build environment and I get the expected results. Does anyone know why I would be getting such a weird result in my application? Or does anyone have another/better way of installing a .inf driver with a ClickOnce application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

永言不败 2024-11-07 19:54:15

如果将 -536870347 转换为十六进制,则会得到 0xe0000235 - 快速搜索发现它在 setupapi.h 中定义为 ERROR_IN_WOW64解释是:

如果函数以 32 位形式返回 ERROR_IN_WOW64
应用程序,该应用程序是
在64位系统上执行,即
不允许。

If you translate -536870347 to hex you get 0xe0000235 - a quick search finds that this is defined in setupapi.h as ERROR_IN_WOW64 and the explanation is:

If the function returns ERROR_IN_WOW64 in a 32-bit
application, the application is
executing on a 64-bit system, which is
not allowed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文