Announcement

Collapse
No announcement yet.

SHELL statement

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

  • SHELL statement

    Hi

    Using PB/DLL 6 compiler I SHELL two different EXE programs:

    ...Code
    SHELL "ProgramA testA"
    ...Code
    SHELL "ProgramB testB"
    ...Code

    If I run ProgramA first and then ProgramB, the control
    after execution of ProgramB does not return to the program,
    the program has to be restarted.
    But if I run ProgramA or ProgramB only control
    returns to the program normally.
    Any idea why it hangs?

    Branko



    ------------------
    http://www.fg.uni-mb.si/lak/ocean


    Structural Engineering Software OCEAN2006
    Slovenia

  • #2
    Branko,

    SHELL is a very useful statement in that it runs another program
    synchronously where the SHELL() function runs another program
    asynchronously.

    The catch is with the SHELL statement is that it does not return control
    back to your program until the SHELLed program is closed.

    I would be inclined to make sure each program is closed properely before
    you call the next one otherwise control will not be returned to your
    program.

    Regards,

    [email protected]

    ------------------
    hutch at movsd dot com
    The MASM Forum - SLL Modules and PB Libraries

    http://www.masm32.com/board/index.php?board=69.0

    Comment


    • #3
      I'm afraid it is not so simple.

      In ProgramB I destroy application by "DestroyWindow hWnd",
      if it is run standalone it closes program
      properly, but if it is run from Calling program using SHELL
      it doesn't , calling program just hangs.

      Any other solutions?

      Regards
      Branko

      ------------------
      http://www.fg.uni-mb.si/lak/ocean


      Structural Engineering Software OCEAN2006
      Slovenia

      Comment


      • #4
        It actually sounds most likely that ProgramB is not closing properly (even if the window is closed, the app's message pump is probably still running).

        As a result, the main application actually never returns from the SHELL statement that launched ProgramB, because ProgramB has not actually finished running!

        So, does DestroyWindow() close it's own window, or are you trying to do this from/to another app? Also, under what conditions are you using DestroyWindow() ? How is the message pump constructed in ProgramB?

        With a "standard" SDK-style app, you would close a window by sending %WM_CLOSE. This results in a %WM_DESTROY message, and in response to this message, your app should call PostQuitMessage() to ensure that the message pump is terminated.

        However, with dialog based app's, you need to use EndDialog() or DIALOG END (DDT) instead of DestroyWindow(). If the dialog is modeless, you still need to signal the message pump to close at the right time. The best method for this will depend on what your code is doing, but generally, some kind of flag that indicates that the target window has been destroyed will work. For DDT dialog suggestions, see DIALOG DOEVENTS in the help file.

        So, in summary, your problem is most likely to be in the design/implementation of ProgramB, and not the SHELL statement at all.

        Post the code to ProgramB and lets see what we can do to help.


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Branko,

          Just give this a whirl to terminate the second app cleanly,

          SendMessage hWnd,%WM_SYSCOMMAND,%SC_CLOSE,ByVal %NULL

          Sending this message is like pressing the system close button
          on the title bar.

          Regards,

          [email protected]

          ------------------
          hutch at movsd dot com
          The MASM Forum - SLL Modules and PB Libraries

          http://www.masm32.com/board/index.php?board=69.0

          Comment


          • #6
            Lance and Steve

            well, i've closed dialog in ProgramB
            DIALOG END hInfoOkno
            and closed app by
            SendMessage hWndMain, %WM_SYSCOMMAND,%SC_CLOSE, ByVal %NULL

            It seems to me that problem lies in the size of the problem.
            If (ProgramB solves the equations, dimensioning of matrices depends on
            the size of the problem) the number of equations
            is moderate, then return controls to the calling program,
            but if size increases i run into problems,
            though ProgramB DOES NOT complain at all!
            Is it possible?
            I'm using W2000 Pro OS.

            Thanks
            Branko


            ------------------
            http://www.fg.uni-mb.si/lak/ocean


            Structural Engineering Software OCEAN2006
            Slovenia

            Comment


            • #7
              Possible? Yes (anything is possible!). Likely? I don't *believe* so.

              I would suspect that there is still some error condition in your program that you are not checking for, or that your message loop is still not closing. While you use DIALOG END, you have not given us enough information as to whether your dialog is modal or modeless, and whether you have checked that the message pump is actually terminating.

              Really, you are going to have to show us some source code to provide more specific help. Sorry!


              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment


              • #8
                Branko,

                I use the SHELL statement with installations that work fine on everything
                from early win95 to winME with no problems at all and some of the EXE
                files being run are in megabytes so it is not a problem with either the
                SHELL statement or the application size, it is still a problem of the
                application not closing properly under some conditions.

                Because SHELL as a statement is synchronous, you will continue to get this
                effect until you work out how to close the second application cleanly.

                Just post the basic logic of your application so we know what it is and the
                rest should be reasonably straight forward.

                Regards,

                [email protected]

                ------------------
                hutch at movsd dot com
                The MASM Forum - SLL Modules and PB Libraries

                http://www.masm32.com/board/index.php?board=69.0

                Comment


                • #9
                  I know enough situations, when Dialog End (SendMessage) doesn't work.
                  That's why I use PostMessage.


                  ------------------
                  E-MAIL: [email protected]

                  Comment


                  • #10
                    Really? How about telling us about some of them, Semen!

                    In every single case I've seen, the problem is with the implementation of the dialog and/or message pump, not DIALOG END.

                    Also, how does SendMessage() figure in DIALOG END?

                    ...?


                    ------------------
                    Lance
                    PowerBASIC Support
                    mailto:[email protected]su[email protected]</A>
                    Lance
                    mailto:[email protected]

                    Comment


                    • #11
                      Lance

                      I would like to send you sample Code
                      but don't know how to include it from file into this Reply!!!

                      sorry
                      Branko

                      ------------------
                      http://www.fg.uni-mb.si/lak/ocean


                      Structural Engineering Software OCEAN2006
                      Slovenia

                      Comment


                      • #12
                        Lance --
                        Well ...
                        Situation #1 - Thread.

                        Code:
                           #Compile Exe
                           #Register None
                           #Dim All
                           #Include "win32api.inc"
                        
                           Global hDlg2 As Long
                           
                           Function Thread1(ByVal hDlg&)As Long
                              Dialog New hDlg&, "TestB", 120,100,100,100 To hDlg2
                              Dialog Show Modal hDlg2
                              MsgBox "Finished"
                           End Function
                          
                           CallBack Function Btn1
                              PostMessage hDlg2, %WM_SYSCOMMAND, %SC_CLOSE, 0
                           End Function
                        
                           CallBack Function Btn2
                              SendMessage hDlg2, %WM_SYSCOMMAND, %SC_CLOSE, 0
                           End Function
                        
                           CallBack Function Btn3
                              Dialog End hDlg2
                           End Function
                        
                           Function PbMain
                              Local hDlg As Long, t As Long
                              Dialog New 0, "TestA", , , 100, 80, %WS_CAPTION Or %WS_SYSMENU To hDlg
                              Control Add Button, hDlg,101, "PostMessage (+)", 10, 10, 80, 15 Call BTN1
                              Control Add Button, hDlg,102, "SendMessage (-)", 10, 30, 80, 15 Call BTN2
                              Control Add Button, hDlg,103, "Dialog End  (-)", 10, 50, 80, 15 Call BTN3
                              Thread Create Thread1(0) To t
                              Thread Close t To t
                              Dialog Show Modal hDlg
                           End Function
                        Sample #2 - Shell

                        B.Bas (compile it)
                        Code:
                           #Compile Exe
                           #Register None
                           #Dim All
                           #Include "win32api.inc"
                        
                           Function PbMain
                              Local hDlg As Long
                              Dialog New 0, "TestB", , , 100, 80, %WS_CAPTION Or %WS_SYSMENU To hDlg
                              Dialog Show Modal hDlg
                              MsgBox "Finished"
                           End Function

                        Program A.Bas (Shells B)

                        Code:
                           #Compile Exe
                           #Register None
                           #Dim All
                           #Include "win32api.inc"
                        
                           CallBack Function Btn1
                              PostMessage FindWindow("", "TestB"), %WM_SYSCOMMAND, %SC_CLOSE, 0
                           End Function
                        
                           CallBack Function Btn2
                              SendMessage FindWindow("", "TestB"), %WM_SYSCOMMAND, %SC_CLOSE, 0
                           End Function
                        
                           CallBack Function Btn3
                              Dialog End FindWindow("", "TestB")
                           End Function
                        
                           Function PbMain
                              Local hDlg As Long, t As Long
                              Dialog New 0, "TestA", 0, 0, 100, 80, %WS_CAPTION Or %WS_SYSMENU To hDlg
                              Control Add Button, hDlg,101, "PostMessage (+)", 10, 10, 80, 15 Call BTN1
                              Control Add Button, hDlg,102, "SendMessage (-)", 10, 30, 80, 15 Call BTN2
                              Control Add Button, hDlg,103, "Dialog End  (-)", 10, 50, 80, 15 Call BTN3
                              t = Shell("b.Exe")
                              Dialog Show Modal hDlg
                           End Function
                        ------------------
                        E-MAIL: [email protected]

                        Comment


                        • #13
                          DIALOG END, like EndDialog(), should *ONLY* be used in the dialog box procedure for the target dialog. Neither of your examples obey this rule.

                          See EndDialog() in WIN32.HLP for more information.



                          ------------------
                          Lance
                          PowerBASIC Support
                          mailto:[email protected][email protected]</A>
                          Lance
                          mailto:[email protected]

                          Comment


                          • #14
                            Branko,

                            What we need is the basics of how you have created the called
                            applications. Depending on if you have used CreateWindowEx() for a normal
                            window style app, an API style MODAL or MODELESS dialog or if you have
                            used the PowerBASIC DDT to create the called apps, there are different
                            methods required to properly close each type.

                            The function call,

                            SendMessage hWnd,%WM_SYSCOMMAND,%SC_CLOSE,ByVal %NULL

                            will close most things but to properly close your application so that control
                            returns to the caller from the SHELL statement, each method is specific.

                            All you need to do is paste in the code that creates the called application,
                            it is a lot easier to read in the forum if you use the notation enclosed in
                            square brackets,

                            "code" on the line before the code and

                            "/code" on the next line after the code.

                            Once we know what the app type is, there are many people here who can help you.

                            Regards,

                            [email protected]


                            ------------------
                            hutch at movsd dot com
                            The MASM Forum - SLL Modules and PB Libraries

                            http://www.masm32.com/board/index.php?board=69.0

                            Comment


                            • #15
                              I am not sure that I understand what you are saying, Lance
                              Is 'Dialog End' a statment that has to be executed inside
                              a Callback Function for the target Dialog?
                              Is that a new addition to PB documentation for Dialog End?
                              ---
                              I am asking because you frequently advice us to look up API-call in
                              MSDN.Am I supposed to know that the documentation for Dialog End is to be found
                              in MSDN under EndDialog?
                              ---
                              This is perhaps unrelated,
                              But, where do I find documentation on TCP NOTIFY? I understand what wMsg will contain.
                              what about wParam and lParam what will TCP NOTIFY put in there when the handled event occur?
                              This is an internal Powerbasic statment, but as I cannot find any
                              information in PB-documentation, I have searched MSDN but only
                              come up with one unrelated hit.





                              ------------------
                              Fred
                              mailto:[email protected][email protected]</A>
                              http://www.oxenby.se

                              Fred
                              mailto:[email protected][email protected]</A>
                              http://www.oxenby.se

                              Comment


                              • #16
                                DIALOG END is a wrapper for EndDialog(), so the same basic rules apply to both the statement and the API call.

                                Regarding TCP_NOTIFY, I don't have any documentation to hand (I'm not at my Dev PC), but if you post a new query to the Internet Programming forum (so we don't get too far off-topic here!), I'll see what I can dig up for you.

                                getting back to the original topic... Branko needs to post some code or email it to Tech Support... the ball is in his court now!




                                ------------------
                                Lance
                                PowerBASIC Support
                                mailto:[email protected][email protected]</A>
                                Lance
                                mailto:[email protected]

                                Comment


                                • #17
                                  Oh, I forgot to mention that the next update to the documentation for DIALOG END will include these notes!


                                  ------------------
                                  Lance
                                  PowerBASIC Support
                                  mailto:[email protected][email protected]</A>
                                  Lance
                                  mailto:[email protected]

                                  Comment


                                  • #18
                                    Lance,
                                    As I don't know how to include file into this reply
                                    i've sent you sample code by Email

                                    Branko

                                    ------------------
                                    http://www.fg.uni-mb.si/lak/ocean


                                    Structural Engineering Software OCEAN2006
                                    Slovenia

                                    Comment


                                    • #19
                                      Originally posted by Lance Edmonds:
                                      DIALOG END, like EndDialog(), should *ONLY* be used in the dialog box procedure for the target dialog. Neither of your examples obey this rule.
                                      See EndDialog() in WIN32.HLP for more information.
                                      Lance --
                                      According your interpretation a code below should not work, but it works.
                                      Code:
                                         #Compile Exe
                                         #Register None
                                         #Dim All
                                         #Include "WIN32API.INC"
                                      
                                         Global hDlg As Long, hDlg1 As Long
                                         
                                         CallBack Function DlgProc1
                                            If (CbMsg = %WM_COMMAND) And (CbCtl = 101) Then Dialog End hDlg
                                         End Function
                                      
                                         CallBack Function DlgProc
                                            If CbMsg = %WM_DESTROY Then MsgBox "hDlg has been destroyed"
                                         End Function
                                      
                                         
                                         Function PbMain
                                            Dialog New 0, "hDlg", 100, 100, 100, 100, %WS_CAPTION To hdlg
                                            Dialog New 0, "hDlg1", 300, 300, 100, 15, %WS_CAPTION To hdlg1
                                            Control Add Button, hDlg1, 101, "Stop hDlg", 0, 0, 100, 15
                                            Dialog Show Modeless hDlg1 Call DlgProc1
                                            Dialog Show Modal hDlg Call DlgProc
                                         End Function
                                      Note, EndDialog has hDlg as a first parameter.
                                      Results of EndDialog, as I understand, are equal to SDK WM_CLOSE + PostQuitMessage.

                                      ------------------
                                      E-MAIL: [email protected]

                                      Comment


                                      • #20
                                        Best to ask Microsoft why this works when the EndDialog() API says it should not...



                                        ------------------
                                        Lance
                                        PowerBASIC Support
                                        mailto:[email protected][email protected]</A>
                                        Lance
                                        mailto:[email protected]

                                        Comment

                                        Working...
                                        X