Search code examples
c#debuggingwinapigetlasterror

Negative GetLastWin32Error()


I am wondering how to debug (or what to do actually) a negative value of Marshal.GetLastWin32Error()?

I have working on my PC peace of code, suddenly it doesn't works on another PC and I have no clue what to do, because I don't know what errors is there.

Here is code (essential part I think):

[DllImport("setupapi.dll", SetLastError = true)]
static extern bool SetupDiChangeState(IntPtr deviceInfoSet, [In] ref SP_DEVINFO_DATA deviceInfoData);

// and then somewhere
if (!SetupDiChangeState(info, ref device))
    throw new Exception(string.Format("Error({0}) SetupDiChangeState", Marshal.GetLastWin32Error()));

Exception text on other PC is

Error(-536870389) SetupDiChangeState

It's not listed here.


Solution

  • Error(-536870389) SetupDiChangeState

    It is 0xE000020B, and perhaps corresponds to ERROR_NO_SUCH_DEVINST.

    See your DIFxAPI.h.