dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.75k stars 190 forks source link

Can not GetLastError #430

Closed hedandan1989 closed 9 months ago

hedandan1989 commented 9 months ago
bool isVaild = Vanara.PInvoke.AdvApi32.LogonUser(username, DomainName, password, AdvApi32.LogonUserType.LOGON32_LOGON_INTERACTIVE, AdvApi32.LogonUserProvider.LOGON32_PROVIDER_WINNT50, out var token);
if (isVaild == false)
{
    var error = Vanara.PInvoke.Win32Error.GetLastError(); //can not get the error
    Vanara.PInvoke.HRESULT errorHresult = error.ToHRESULT();
    errorCode = errorHresult.Code;
    message = errorHresult.FormatMessage();

    //can get the error
    errorCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
    message = new Win32Exception(errorCode).Message;
}
token.Dispose();

Windows 10 22H2

dahall commented 9 months ago

Made change in nullability fork for next release