CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2001
    Posts
    91

    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.



  2. #2
    Join Date
    Apr 2000
    Posts
    737

    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

  3. #3

    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>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured