Announcement

Collapse
No announcement yet.

Exit error code using WINMAIN?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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]

    http://www.v3space.com/a/a39/202/ (currently inactive)

  • #2
    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]

    Comment


    • #3
      Semen,

      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]

      http://www.v3space.com/a/a39/202/

      Comment


      • #4
        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....


        ------------------
        Scott
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment


        • #5
          Clay,

          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]

          Code:
          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
          
          'PBCC
          #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
              LOCAL Si AS STARTUPINFO
              LOCAL Pi AS PROCESS_INFORMATION
              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&)
                    'Ec&=256
          	  rc& = GetExitCodeProcess(pi.hProcess,Ec&)
          	  FUNCTION=Ec&
          	  CALL CloseHandle(pi.hProcess)
                    CALL CloseHandle(pi.hThread)
                 END IF
              END IF
          END FUNCTION
          
          
          Function PBMain() as long
          
             ret&=dvshell(command$,1,%INFINITE)
             if ret&>255 then 
                function=255
             else
                function=ret&
             end if
                
          end function
          ------------------
          James Moneypenny

          [This message has been edited by James Moneypenny (edited July 15, 2001).]
          James Moneypenny
          mailto:[email protected][email protected]</A>

          Comment

          Working...
          X