1

I've tried invoking UpdateDriverForPlugAndPlayDevices three different ways. Here they are:

 [DllImport("newdev.dll", CharSet = CharSet.Ansi, SetLastError = true)]
    public static extern bool UpdateDriverForPlugAndPlayDevices(
        IntPtr hwndParent,
        [MarshalAs(UnmanagedType.LPWStr)] string HardwareId,
        [MarshalAs(UnmanagedType.LPWStr)] string FullInfPath,
        uint InstallFlags,
        ref bool bRebootRequired);

    [DllImport("newdev.dll", SetLastError = true, CharSet = CharSet.Auto)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool UpdateDriverForPlugAndPlayDevices(
        [In, Optional]  IntPtr hwndParent,
        [In] string HardwareId,
        [In] string FullInfPath,
        [In] uint InstallFlags,
        [Out, Optional] bool bRebootRequired
        );

    [DllImport("newdev.dll", SetLastError = true)]
    public static extern bool UpdateDriverForPlugAndPlayDevices(
        IntPtr hwndParent,
        string HardwareId,
        string FullInfPath,
        uint InstallFlags,
        ref bool bRebootRequired
        );

Regardless of which of these I call, the returned result is false, and the following call to Marshall.GetLastWin32Error() gives an error code of -536870347. I've searched and searched and not found any such error code.

I feel like the problem is with the way I'm defining the function because I can pass nonsensical parameters to my call to UpdateDriverForPlugAndPlayDevices() and I still get the same error code.

The previous calls leading up to this work fine, I'm using pinvoked calls to SetupDiGetClassDevsW(), SetupDiEnumDeviceInfo(), SetupDiGetDeviceRegistryProperty() and SetupCopyOEMInf() and they all act in the expected ways.

Can someone tell me what this error means, or what I'm doing wrong? Thank you!

Trevor
  • 172
  • 2
  • 8

2 Answers2

3

gives an error code of -536870347

Always convert such large numbers to hex. You'll get 0xE0000235. That googles very well, it is ERROR_IN_WOW64. Or in other words, you cannot make SetupDi calls from a 32-bit program on the 64-bit version of Windows.

Right-click your EXE Project, Properties, Build tab. Remove the jitter forcing so it runs as AnyCPU. Untick the "Prefer 32-bit" option if you see it. Repeat for the Release configuration.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thank you Hans! I had no idea about the hex conversion (obviously) - very useful piece of knowledge. – Trevor Sep 24 '14 at 00:52
1
    [DllImport("NewDev.dll", CharSet = CharSet.Auto, EntryPoint = "UpdateDriverForPlugAndPlayDevices")]
    [SecurityCritical]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal extern static bool UpdateDriverForPlugAndPlayDevices(IntPtr hwndParent,
                                                                [MarshalAs(UnmanagedType.LPWStr)]String szHardwordID,
                                                                [MarshalAs(UnmanagedType.LPWStr)]String szINFName,
                                                                uint installFlags, IntPtr bRebootRequired);
Utmost
  • 51
  • 1