GetLastError returning different values in debug mode & EXE
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.
Re: GetLastError returning different values in debug mode & EXE
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
Re: GetLastError returning different values in debug mode & EXE
try to test
If GetLastError() <> 0 then
instead of
If GetLastError() = 123 then
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
</center>