Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't get GetLastError() to return a value?!
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01101255
Message ID:
01101362
Views:
10
Well, I'm glad you found that you're still sane ... I'm still wondering about myself! :)

I created a project with the following code and built it into an .exe and ran the .exe. Still got 0 even when entering a bogus password.
DECLARE integer GetLastError IN kernel32
DECLARE integer CloseHandle IN kernel32 integer hObject
DECLARE integer LogonUser IN advapi32 string lpzUser, string lpzDomain, string lpzPass, integer dwLogonType, integer dwLogonProvider, integer @phToken

nToken = 0

IF LogonUser("test_user","domain.org",INPUTBOX("Password:"),3,0,@nToken) = 0
   lnResult = GetLastError()
   = MESSAGEBOX(lnResult)
ELSE
   = CloseHandle(nToken)
ENDIF

RELEASE ALL
CLEAR DLLS
How are you running your code ot get it to work?

>No domain available, local user. Though some funny results I have -- you'll probably be laughing :)
>
>Look at this code:
>
>LOCAL nToken, cProcInfo, cStartInfo, nCreationFlags, nLastError
>nToken = 0
>
>= LogonUser(cUsr, cDomain, cPwd,;
>	LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, @nToken)
>
>nLastError = GetLastError()
>
>IF nToken = 0
>* 1326 = ERROR_LOGON_FAILURE
>* 1327 = ERROR_NO_SUCH_MEMBER
>* 1385 = ERROR_LOGON_TYPE_NOT_GRANTED
>	? "Error:", nLastError
>	RETURN .F.
>ENDIF
>
>When executed as a single piece, the code returns valid error code as expected.
>
>Even if logon error happens, the code returns zero as LastError code when executed (ATTENTION!!!)
>- in Command Window
>- in Debug mode (step by step)
>- with an artificial delay inserted right after the LogonUser call
>
>Looks like the LastErrorCode value does not survive long after the LogonUser call, some process quickly sets it back to zero.
>
>I checked several times just to make sure that I was sane enough :) on Friday afternoon. Let me know if it helps.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform