Skip to content

Kernel#GetLastError() always returns ERROR_SUCCESS - Native#getLastError() returns the correct code #604

@lgoldstein

Description

@lgoldstein

Advapi32Util has 2 methods that wrap the above mentioned API calls - getAccountBySid/Name respectively. The 2 methods work more or less the same - they make an initial call to the LookupAccountXXX method in order to query how much memory they need to allocate. The code expects the initial call to fail with an error code of ERROR_INSUFFICIENT_BUFFER (122). The code checks this by invoking Kernel32.INSTANCE.GetLastError().

Here is the strange bit: the call to LookupAccountXXX does fail, but the reported error code from the Kernel32.INSTANCE.GetLastError() invocation is zero - i.e., success. If I replace the call to Kernel32.INSTANCE.GetLastError() with Native.getLastError(), then indeed ERROR_INSUFFICIENT_BUFFER is reported and the code continues successfully.

This behavior is reproduced every time on my computer - Windows 10 Home edition 64 bit with VS 2015 update 1 - whenever I run Advapi32UtilTest#testGetAccountBySid/Name (respectively).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions