1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Use of @WINAPI

Discussion in 'Support' started by Raistlin, Jun 13, 2008.

  1. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    0
    I want my alias to return an error code. QUIT doesn't suit since it quits a batch file along with an alias. So I want to use WinAPI's SetLastError. But executing
    Code:
    echo %@winapi[Kernel32.dll,SetLastError,20] > nul
    echo %? # %_?
    returns "0 # 0". Neither exit code for last internal command nor exit code for last external command was changed. I don't understand why. Any ideas?
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,888
    Likes Received:
    30
    On Fri, 13 Jun 2008 12:59:10 -0500, you wrote:


    Functions (@WINAPI) don't set _? or ?. _? will be the return code of ECHO (the
    last internal command). This may not be very satisfying but you could set ?
    with a batfile:

    v:\> type seterror.btm
    quit %1

    v:\> alias foo
    echo foo & seterror.btm 22

    v:\> foo
    foo

    v:\> echo %?
    22
     
  3. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    0
    Thank you. This thought came into my mind, too :).
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,888
    Likes Received:
    30
    On Fri, 13 Jun 2008 13:38:43 -0500, you wrote:


    I wrote a trivial plugin command to set _?.

    INT WINAPI SETERR ( WCHAR * psz )
    {
    return _wtoi(psz);
    }

    It works. Perhaps Rex would overload the RETURN command so it would set _? when
    used in an alias.

    v:\> alias foo `echo foo & seterr 666`

    v:\> foo & echo %_?
    foo
    666
     
  5. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    0
    Why RETURN? It's better to add a new option to QUIT - to make it possible to quit just an alias but not parent batch file.
     
  6. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,188
    Likes Received:
    11
    The problem is that ALIAS's are not commands/functions unto themselves.
    They are just simple text substitution macros. You can see the true
    expression by pressing ctrl+f.

    So, using Vince's example:
    Code:
    alias foo=`echo foo & seterr 22`
    
    if you type foo, then press Ctrl+F, you'll see foo get replaced with: echo
    foo & seterr 22

    -Scott




    Raistlin <>
    06/13/2008 04:33 PM
    Please respond to



    To
    Samintz@ra.rockwell.com
    cc

    Subject
    RE: [Support-t-193] Re: Use of @WINAPI






    Quote:
    Originally Posted by vefatica
    Perhaps Rex would overload the RETURN command so it would set _? when used
    in an alias
    Why RETURN? It's better to add a new option to QUIT - to make it possible
    to quit just an alias but not parent batch file.
     
  7. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    0
    Then all we need is new command SETERROR. Calling external batch file or using external plugin ain't good ways to perform such simple and trivial operation as setting the errorlevel.
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,888
    Likes Received:
    30
    On Fri, 13 Jun 2008 15:33:45 -0500, you wrote:


    QUIT, RETURN, ... even EXIT, it doesn't matter to me which does it ...
    whatever's easier I suppose.
     

Share This Page