PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: J P Eskdale on December 04, 2013, 09:15:30 PM

Title: Help Debuging
Post by: J P Eskdale on December 04, 2013, 09:15:30 PM
I have a program that consists of 2 areas
I developed part 1 and was all working
I developed part 2 and is working


Both parts make a call to a form which contains a WebBrowser control.  This used to work perfectly but has stopped working in that as soon as the Form containing the WebBrowser is called the program just completely hangs. The Task bar does show an additional window has been created but that is all.

So Instead of calling the form with the WebBrowser I created an empty form and called that instead and this worked.
So Next I added a WebBrowser control nothing else and set the browser properties to display the www.bbc.co.uk which it does in design view.  I put a debug statement immediately before the call to
FrmWeb_show( HWND_FORMMAIN, %False) and put one after.  The one before gets displayed but not the one after

I tried putting a debug statement in the FRMWEB_WM_CREATE handler but this doesn't get called

The question is how is the best way to debug this as its getting lost in the Firefly generated code.

The problem only occurs when the webbrowser control is on the form.  And it works fine in other programs and it did originally in this program.  I need to put some debug code in the Firefly generated code to find out where it is going. How?  Unless some genius has a great idea of what could be crashing it.

Thanks
Jon
Title: Re: Help Debuging
Post by: J P Eskdale on December 04, 2013, 10:04:33 PM
OK got the generated code to compile in the

Function FRMWEB_Show(
I added the 2 outputdebugstring commands
The initial one gets displayed but it never returns from the pWindow.CreateWindow

Any idea where should I look now

Thanks

Jon


      outputdebugstring "FrmWeb_Show about to CreateWindow"
    ' // Create the main window
    pWindow.CreateWindow( hWndParent, _
                          "Web viewer", _
                          0, 0, 500, 370, _
                          %WS_POPUP Or %WS_THICKFRAME Or %WS_CAPTION Or %WS_SYSMENU _
                                  Or %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX Or %WS_CLIPSIBLINGS _
                                  Or %WS_CLIPCHILDREN , _
                          %WS_EX_WINDOWEDGE Or %WS_EX_CONTROLPARENT _
                                  Or %WS_EX_LEFT Or %WS_EX_LTRREADING Or %WS_EX_RIGHTSCROLLBAR _
                                 , _
                          CodePtr( FRMWEB_FORMPROCEDURE ) )
    outputdebugstring "FrmWeb_Show back from CreateWindow"
    If IsWindow(pWindow.hWnd) = 0 Then
       Function = -1: Exit Function
    End If
Title: Re: Help Debuging
Post by: J P Eskdale on December 05, 2013, 06:57:52 AM
OK Narrowed it down more but even more confused now

Problem is in AddControl in cWindow

Program flow is it calls AddWebrowserControl
which then calls AddControl
which calls CreateWindowEx but this never returns
This is the AddContol method from cWindow

     LOCAL hCtl AS DWORD
      outputdebugstring "AddControl -1"
      IF hParent = 0 THEN hParent = m_hwnd
      IF BITS(LONG, dwStyle) = -1 THEN dwStyle = %WS_VISIBLE OR %WS_TABSTOP
      IF BITS(LONG, dwExStyle) = -1 THEN dwExStyle = 0
      ' // Make sure that the control has the WS_CHILD style
      dwStyle = dwStyle OR %WS_CHILD
      ' // Create the control
      IF bNoScale THEN
      outputdebugstring "AddControl -2"
         hCtl = CreateWindowEx(dwExStyle, BYCOPY strClassName, BYCOPY strTitle, _
                dwStyle, x, y, nWidth, nHeight, _
                hParent, cID, m_hInstance, BYVAL lpParam)
      ELSE
      outputdebugstring "AddControl -3 " + hex$(dwExStyle) + ", " + strClassName + ", " + strTitle + ", " + _
                        hex$(dwStyle) + ", " + str$(x * m_rx) + ", " + str$(y * m_ry) + ", " + str$(nWidth * m_rx) + _
                        ", " + str$( nHeight * m_ry) + ", " + hex$(hParent) + ", " + str$(cID) + _
                        ", " + hex$(m_hInstance) + ", " + hex$(lpParam)
         hCtl = CreateWindowEx(dwExStyle, BYCOPY strClassName, BYCOPY strTitle, _
                dwStyle, x * m_rx, y * m_ry, nWidth * m_rx, nHeight * m_ry, _
                hParent, cID, m_hInstance, BYVAL lpParam)
      END IF
      outputdebugstring "AddControl -4 " + str$(hCtl)


The Debug output is this
[16056] AddWebBrowserControl - 1
[16056] AddControl -1
[16056] AddControl -3 0, OC_WIN32, Shell.Explorer, 56000000,  80,  54,  360,  218, 3C1840,  1000, 200000, 70
But it never returns we don't get the AddControl -4

On a simpler program that works
The Debug output is this
[13364] AddWebBrowserControl - 1
[13364] AddControl -1
[13364] AddControl -3 0, OC_WIN32, Shell.Explorer, 56000000,  31,  26,  425,  318, 1407DC,  1000, 200000, 70
[13364] AddControl -4  3020910

So what is wrong?

Thanks for any help
Jon
Title: Re: Help Debuging
Post by: José Roca on December 05, 2013, 07:20:24 AM
Almost always the problem is in the code not shown. In pWindow.CreateWindow, from where comes pWindow?
Title: Re: Help Debuging
Post by: J P Eskdale on December 05, 2013, 07:45:08 AM
Hi Jose - Thanks

This is the beginning of the function all generated by FireFly apart from the outputdebug strings I added for debugging


Function FRMWEB_Show( _
                    ByVal hWndParent As Dword, _
                    ByVal ShowModalFlag As Long, _
                    Optional ByVal UserData As Long _
                    )  As Long

    Local IsMDIForm as Long
   
    ' // Create an instance of the class
    Local pWindow As IWindow
    pWindow = Class "CWindow"
    If IsNothing(pWindow) Then Function = -1: Exit Function
   
    pWindow.ClassName = "FORM_ISAF EVENTS_FRMWEB_CLASS"
   
    ' // Set the flag if this is an MDI form we are creating
    IsMDIForm = %FALSE

    ' // Save the optional UserData to be checked in the Form Procedure CREATE message
    App.ReturnValue = UserData
   

    ' // Always ensure that we enable High DPI
    pWindow.DPI = -1

      outputdebugstring "FrmWeb_Show about to CreateWindow"
    ' // Create the main window
    pWindow.CreateWindow( hWndParent, _


I've attached the whole include file for the form which is generated by FireFly

Thanks Jon
Title: Re: Help Debuging
Post by: J P Eskdale on December 05, 2013, 12:49:55 PM
I've been trying to step through the disassembled code
If it helps anyone it locked up while making a subroutine call from within the OLE32 module

Attached is a screen shot when the createWindowEx was called showing the Stack which looks OK

Regards
Title: Re: Help Debuging
Post by: David Kenny on December 05, 2013, 02:57:43 PM
Jon,

Have you tried the PB debugger?  It's got to be more useful than a generic win32 disassembler\debugger.
Title: Re: Help Debuging
Post by: J P Eskdale on December 05, 2013, 03:05:34 PM
Thanks David,
But its not that simple - I have determined at what point it crashes/hangs in PowerBasic

The code is PowerBasic code but generated by FireFly not code that I've written - It makes an API call to CreateWindowEx but this call never returns.

If I generate a simple program to test the feature it works fine but when its part of a larger program it does not.

Question is where to look

Jon
Title: Re: Help Debuging
Post by: J P Eskdale on December 05, 2013, 05:56:25 PM
Still in trouble with this  :(
What is the significance of Shell.Explorer as the Title when adding the control.  In desperation I tried making this blank just to see what would happen and although I don't get a browser it doesn't hang

Jon

Title: Re: Help Debuging
Post by: José Roca on December 05, 2013, 07:10:55 PM
> What is the significance of Shell.Explorer as the Title when adding the control

It is the ProgID of Internet Explorer. Without it, an instance of the WebBrowser control can't be created.

Which version of IE are you using? It has been working until version 10. I have not tested it with version 11.

If you make a simple test that uses the WebBrowser control, does it work?
Title: Re: Help Debuging
Post by: J P Eskdale on December 05, 2013, 07:19:46 PM
Hi Jose,

It is version 11 but as I said in the earlier posts a simple test works.  That is what is so frustrating.  I'm not saying that is not my code that is causing it but I can't see how - This part of it is the simple bit - I've even recreated the forms to test it out - Any suggestions welcome

And it was working with this program until recently.  I don't understand why it stopped I didn't change any of the web form at all

I've spent ages on this program and I need to get it finished and on with other things - Its not as if I was even selling it.  But I said I would do it for the sailing community so I need to get done.
Jon
Title: Re: Help Debuging
Post by: José Roca on December 05, 2013, 07:31:55 PM
I'm trying to figure it. I don't have all the code, so I can't know if something is missing.

Does your program use %USEWEBBROWSER = 1 at the beginning? This is essential.
Title: Re: Help Debuging
Post by: J P Eskdale on December 05, 2013, 07:49:02 PM
Hi  Jose

Yes it does as this is put in by FireFly

I've PM'd you a link to a zip of the release directory which has all the code in it.  It's got in a bit of a mess at the moment as I've been trying all sorts of things to get it to work but the code then should compile and run.

If you run it and click on the "Click here to contact ISAF" button that should open the browser and it used to but now hangs

Thanks Jon
I am away tomorrow but back Saturday
Title: Re: Help Debuging
Post by: José Roca on December 05, 2013, 08:07:56 PM
The only part in the AddWebBrowser method that could hang the application is


               DO
                  ' // Processes pending messages
                  AfxPumpMessages
                  ' // Retrieves the ready state
                  IF pIWebBrowser2.ReadyState = %READYSTATE_COMPLETE THEN EXIT DO
               LOOP


but it should not happen, since you said that a simple test works.
Title: Re: Help Debuging
Post by: J P Eskdale on December 05, 2013, 08:13:44 PM
Hi Thanks -
But it doesn't get that far as it never returns from the
hCtl = ME.AddControl ($OC_CLASSNAME, hParent, cID, strTitle, x, y, nWidth, nHeight, dwStyle, dwExStyle, lpParam, %NULL, bNoScale)
About 22 source code line before the Do in your message

Jon
Title: Re: Help Debuging
Post by: José Roca on December 05, 2013, 10:46:59 PM
Sorry, but I can't find what causes the hang. I have written the test below, that works perfectly, but when I replace the FRMWEB_Show function and callback with mine in your application, it hangs. Can't figure why. I'm using similar code in my CSED editor and it works.


#COMPILE EXE
#DIM ALL
'%UNICODE = 1
%USEOLECON = 1
%USEWEBBROWSER = 1

' // Include files for external files
#INCLUDE ONCE "CWindow.inc"   ' // CWindow class

%IDC_WB_CONTROL = 101
%IDC_WB_PRINT   = 102
%IDC_WB_PREVIEW = 103

' ========================================================================================
FUNCTION FRMWEB_Show ( _
                    ByVal hWndParent As Dword, _
                    ByVal ShowModalFlag As Long, _
                    Optional ByVal UserData As Long _
                    ) AS LONG

   ' // Create an instance of the class
   LOCAL pPrint AS IWindow
   pPrint = CLASS "CWindow"
   IF ISNOTHING(pPrint) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pPrint.CreateWindow(hWndParent, "Print Preview", 0, 0, 0, 0, _
          %WS_VISIBLE OR %WS_CAPTION OR %WS_POPUPWINDOW, %WS_EX_WINDOWEDGE, _
          CODEPTR(CSED_WB_PrintPreview_WindowProc))
   pPrint.SetClientSize 700, 440
   pPrint.CenterWindow(hwnd, hWndParent)

   LOCAL hCtl AS DWORD
   hCtl = pPrint.AddWebBrowserControl(hwnd, %IDC_WB_CONTROL, "www.bbc.co.uk", NOTHING, 0, 0, pPrint.ClientWidth, pPrint.ClientHeight - 40, -1)

   ' // Add the buttons
   pPrint.AddButton(hwnd, %IDC_WB_PRINT, "&Print", pPrint.ClientWidth - 280, pPrint.ClientHeight - 30, 75, 23, -1)
   pPrint.AddButton(hwnd, %IDC_WB_PREVIEW, "Pre&view", pPrint.ClientWidth - 185, pPrint.ClientHeight - 30, 75, 23, -1)
   pPrint.AddButton(hwnd, %IDCANCEL, "&Close", pPrint.ClientWidth - 90, pPrint.ClientHeight - 30, 75, 23, -1)

   ' // Default message pump (you can replace it with your own)
   pPrint.DoEvents

END FUNCTION
' ========================================================================================

' ========================================================================================
' Editor options callback function.
' ========================================================================================
FUNCTION CSED_WB_PrintPreview_WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   LOCAL pIWebBrowser2 AS IWebBrowser2           ' // IWebBrowser2 interface reference
#IF %DEF(%UNICODE)
   LOCAL szText AS WSTRINGZ * 255                ' // General purpose variable
   LOCAL szPath AS WSTRINGZ * %MAX_PATH          ' // File path
#ELSE
   LOCAL szText AS ASCIIZ * 255                  ' // General purpose variable
   LOCAL szPath AS ASCIIZ * %MAX_PATH            ' // File path
#ENDIF

   SELECT CASE uMsg

      CASE %WM_CREATE
         ' // Disable the owner of the modal window
         EnableWindow GetWindow(hwnd, %GW_OWNER), %FALSE

      CASE %WM_COMMAND

         SELECT CASE LO(WORD, wParam)

            CASE %IDCANCEL
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  SendMessage hwnd, %WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF

            CASE %IDC_WB_PRINT
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // Gets a reference to the IWebBrowser2 interface
                  pIWebBrowser2 = OC_GetDispatch(GetDlgItem(hwnd, %IDC_WB_CONTROL))
                  IF ISOBJECT(pIWebBrowser2) THEN
                     pIWebBrowser2.ExecWB %OLECMDID_PRINT, %OLECMDEXECOPT_PROMPTUSER
                     ' // Releases the interface
                     pIWebBrowser2 = NOTHING
                  END IF
               END IF
               EXIT FUNCTION

            CASE %IDC_WB_PREVIEW
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // Gets a reference to the IWebBrowser2 interface
                  pIWebBrowser2 = OC_GetDispatch(GetDlgItem(hwnd, %IDC_WB_CONTROL))
                  IF ISOBJECT(pIWebBrowser2) THEN
                     pIWebBrowser2.ExecWB %OLECMDID_PRINTPREVIEW, %OLECMDEXECOPT_PROMPTUSER
                     ' // Releases the interface
                     pIWebBrowser2 = NOTHING
                  END IF
                  EXIT FUNCTION
               END IF

         END SELECT

      CASE %WM_CLOSE
         ' // The owner window is enabled in WM_CLOSE rather than WM_DESTROY to
         ' // prevent the application from losing the focus. In WM_DESTROY the
         ' // modal window has already been removed from the screen by the system.
         ' // Because the remaining windows are disabled, the system gives the
         ' // focus to another application.
         EnableWindow GetWindow(hwnd, %GW_OWNER), %TRUE

      CASE %WM_DESTROY
         ' // Close the main window
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Set process DPI aware
   IF AfxGetWindowsVersion => 6 THEN SetProcessDPIAware

   ' // Create an instance of the class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   ' // Note: CW_USEDEFAULT is used as the default value When passing 0's as the width and height
   pWindow.CreateWindow(%NULL, "CWindow with a button", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   ' // Set the client size
   pWindow.SetClientSize 500, 320
   ' // Center the window
   pWindow.CenterWindow

   ' // Add a button
   pWindow.AddButton(pWindow.hwnd, %IDOK, "&View", 350, 250, 75, 23)

   

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   ' // Process window mesages
   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDOK
               FRMWEB_Show(hwnd, 0)
               EXIT FUNCTION
            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

Title: Re: Help Debuging
Post by: José Roca on December 05, 2013, 11:26:36 PM
Found it!


COUNINITIALIZE
COINITIALIZEEX BYVAL %NULL, %COINIT_MULTITHREADED


If you remove these lines, the WebBrowser control will work.

The WebBrowser control must run in a Single Threaded Apartment.
Title: Re: Help Debuging
Post by: J P Eskdale on December 08, 2013, 04:55:40 PM
Hi Jose

Thank you so much - As I mentioned in an earlier post I've been away for a couple of days - Back to the PC today and yes removing those lines fixed the web viewer issue.

I'm not sure I understand the rules of how to use COINITIALIZEX as yet - another learning curve.  They were added as a possible fix for the problem with the threading I was having.  Need to go and do some testing now to see what does and doesn't work

I must just say how much I appreciate you spending the time to look at it for me - If there is anything I can do for you don't hesitate to ask.