1

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?

Community
  • 1
  • 1
TKTS
  • 1,261
  • 1
  • 11
  • 17

1 Answers1

3

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.

John
  • 5,561
  • 1
  • 23
  • 39
  • That makes sense. Is there a better way to ensure I am getting the hex value instead of using Int32 as a return type? – TKTS Apr 14 '11 at 15:45
  • 1
    In the debugger you can right-click on the value and select "hexadecimal display" to see the value as hex. If you print using string.format you can use `{0:X}` – John Apr 14 '11 at 22:43