Click to See Complete Forum and Search --> : GetLastError returning different values in debug mode & EXE


181d6ebe-b1a-58a
September 3rd, 2001, 08:53 PM
hi, this is very strange. same app, same code, but GetLastError returning different values when it's in VB debug mode (inside the VB dev environment) than in standalone EXE. here's the code:

option Explicit

private Declare Function GetLastError Lib "kernel32" () as Long
private Declare Sub SetLastError Lib "kernel32" (byval dwErrCode as Long)

private Sub Command1_Click()
SetLastError 0
SetLastError 123
If GetLastError() = 123 then
MsgBox "last error was set"
else
MsgBox "last error was not set"
End If
End Sub




very simple. but in vb environment, last error was always set and the result is "last error was set". however, if you compile it and run in standalone exe, it will always say "last error was not set"..

any idea??? please help.

thanks.

cksiow
September 3rd, 2001, 09:48 PM
just to tell u that for every API declare, VB will call GetLastError automatically and store it in Err object... so use the Err object instead of calling it directly.


HTH

cksiow
http://vblib.virtualave.net - share our codes

berta
September 4th, 2001, 03:40 AM
try to test

If GetLastError() <> 0 then
instead of
If GetLastError() = 123 then



<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>