No announcement yet.

Exit error code using WINMAIN?

  • Filter
  • Time
  • Show
Clear All
new posts

  • James Moneypenny

    I use the following code to launch a windows app (can launch most any app),
    but the loadapp.exe geneated takes the whole command line and passes it to
    dvShell() function (posted in the source code forum) which lauches the process and wait infinitely for
    the process to finish. When the process does finish it takes the error
    code and sets the exit code to 255 or less. (DOS errorlevel will only return
    a value of 255 or less.)

    If you need the exe then send me an email at [email protected]

    rem Ex: batch file
    loadapp.exe pbdllapp.exe /parameter1 /parameter1 
    if not errorlevel 1 echo there was NO ERROR.
    if errorlevel 1 echo there was an ERROR!!!! of 1 or higher
    if errorlevel 100 echo there was an ERROR!!!! of 100 or higher
    rem end batchfile
    #INCLUDE "\pb\winapi\WIN32API.INC"
    ' dvShell - Returns errorlevel of process and launches process.
    '           CmdLine$=command line and parameters passed that should be launched 
    '           ShowWind&=default window state of lauched program.
    '                     %SW_HIDE                                     
    '                     %SW_SHOWNORMAL                               
    '                     %SW_NORMAL                                   
    '                     %SW_SHOWMINIMIZED                            
    '                     %SW_SHOWMAXIMIZED                            
    '                     %SW_MAXIMIZE                                 
    '                     %SW_SHOWNOACTIVATE                           
    '                     %SW_SHOW                                     
    '                     %SW_MINIMIZE                                 
    '                     %SW_SHOWMINNOACTIVE                          
    '                     %SW_SHOWNA                                   
    '                     %SW_RESTORE                                  
    '                     %SW_SHOWDEFAULT                              
    '                     %SW_MAX                                      
    '           TimeLimit&=milliseconds windows will wait for prcoess to finish.
    '                      passing %INFINITE will tell windows to wait forever.
    ' Usage - if App_PrevInstance("aljsdlkajsdljasdlkjasldkj") then <Another instance
    '         is running>
    FUNCTION dvShell(BYVAL CmdLine$, BYVAL ShowWind&, BYVAL TimeLimit&) as long
        Si.cb = SIZEOF(Si)
        Si.dwFlags = %STARTF_USESHOWWINDOW
        Si.wShowWindow = ShowWind&
        IF CreateProcess("", _
                         BYVAL STRPTR (CmdLine$), _
                         BYVAL %NULL, _
                         BYVAL %NULL, _
                         0, _
                         %NORMAL_PRIORITY_CLASS, _
                         BYVAL %NULL, _
                         BYVAL %NULL, _
                         Si, _
                         Pi) THEN
           CALL WaitForInputIdle(pi.hProcess, %INFINITE)
           IF TimeLimit& THEN
              CALL WaitForSingleObject(pi.hProcess, TimeLimit&)
    	  rc& = GetExitCodeProcess(pi.hProcess,Ec&)
    	  CALL CloseHandle(pi.hProcess)
              CALL CloseHandle(pi.hThread)
           END IF
        END IF
    Function PBMain() as long
       if ret&>255 then 
       end if
    end function
    James Moneypenny

    [This message has been edited by James Moneypenny (edited July 15, 2001).]

    Leave a comment:

  • Scott Turchin
    Isn't there a way to modify the environmental variable (Temp until app ends) so that the dos prog could see it?
    ie, SET ERRORLEVEL=255

    I don't know if that would work or not, app would have to maintain until it was read....


    Leave a comment:

  • Clay Clear

    Yeah, I've already considered using a file, maybe a semaphore file,
    to signal the exit code to the DOS program that calls the 32-bit Windows program.
    BUT, I'm *hoping* that there's a much more straightforward solution.
    The more I think about it, the less likely that I think there is, though,
    as, as far as I know, Windows programs and DOS programs use completely different methods of
    handling exit codes and general runtime errors.

    Thanks for your reply!

    Clay C. Clear

    [email protected]

    Leave a comment:

  • Semen Matusovski
    Clay --
    ShellExecute "returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise" (MSDN).
    To retrieve a code, it's necessary to use CreateProcess.

    Frankly, it's not clear how and what do you start.
    If DOS starts your own 32-bit program, you can return a code by many ways - external file, video buffer (if to call PB/CC) and so on.

    E-MAIL: [email protected]

    Leave a comment:

  • Clay Clear
    started a topic Exit error code using WINMAIN?

    Exit error code using WINMAIN?

    I read in the PB/DLL online Help that, if you use the WINMAIN()
    function in your program, you can return an exit error code by
    assigning the value to the FUNCTION. But, how can I get a *DOS*
    program to receive the error code? The reason I need it is because
    I wrote a Windows docment file printing program (using
    ShellExecute with the "print" command), and it is mainly for use
    with my DOS programs so they have a way to print if I decide to use
    my printer in USB Mode. I tested the error code stuff with a DOS
    program using the QPP 3.0 LoadExec% function, but the return variable
    for the LoadExec% function ALWAYS returns "0", even if the print
    program errors out.

    Any ideas?

    Thanks in advance!

    Clay C. Clear

    [email protected] (currently inactive)