Link to home
Start Free TrialLog in
Avatar of david_johns
david_johns

asked on

Problem with WebBrowser2 based class

Hi,

I have built a class to make the WebBrowser2 and accompanying objects a bit easier to use.  Basically I have handled all the bstr conversion operations necessary to open, close, navigate and so forth inside of class functions so that all operations can be done without having to go through the mess associated.  I have a second class that stores the document elements broken down into dropdowns, textboxes and so forth so that interacting with the document like entering text, selecting options and clicking buttons and hyperlinks can all be a simple one-liner.  I have had one problem from the beginning.  After having navigated with the browser there are always several:

First-chance exception in SuperManager.exe (KERNEL32.DLL): 0x80010108: (no name).

that come up when I close the browser.  After quitting the debugger I get an object dump.  The place of allocation is never given and I have checked and rechecked and it seems that none of my internally allocated stuff gets left over.  The contents of the dump usually contain urls, textbox names, hyperlink texts and so forth.   Any ideas what could be causing this?  I will include the following example function for you to look over and see if I leave the potential of having something left allocated.

int WebDocument::ClickHyperlink(const char *label)
{
      int i;
      
      BSTR bstr;

      char *string;

      HRESULT hr=0;


      for (i=0; i<nHyperlinks; i++)      {
            hr = pHyperlink[i]->get_innerText(&bstr);
            if(hr!=S_OK) return 1000;

            if(bstr==NULL) continue;

            string = ConvertBSTRToString(bstr);
            SysFreeString(bstr);
            
            if(strcmp(string, label)==0)            {
                  hr = pHyperlink[i]->click();
                  if(hr!=S_OK) return 1001;
                  break;
            }

            delete[] string;
      }
      
      if(i==nHyperlinks+1) return 1002; //Not found
      
      return 1;
}

The others follow a similar format.

This problem just means I have a memory leak.  The second problem is more limiting.  I have started using these classes inside worker threads.  I have a pBrowser object attached to theApp and I use it throughout the application when I need to interact with the web.  I have had no problem with sharing an open browser inside the main application thread, but after using it once in a worker thread it is rendered useless.  When the thread closes I get again a bunch of:

First-chance exception in SuperManager.exe (KERNEL32.DLL): 0x80010108: (no name).

When I try to navigate again I get:

First-chance exception in SuperManager.exe (KERNEL32.DLL): 0x800401FD: (no name).
First-chance exception in SuperManager.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.

One of them is probably thrown by me and used to handle the error.

Any ideas?  Are the two problems connected?

Thanks. David
Avatar of jkr
jkr
Flag of Germany image

>>Any ideas?  Are the two problems connected?

If it is only a First-chance exception, you may safely ignore that. See http://support.microsoft.com/default.aspx?scid=kb;en-us;105675 ("105675 - INFO: First and Second Chance Exception Handling")
Avatar of david_johns
david_johns

ASKER

jkr,

Thanks for the insight.  I was not so much worried about the exceptions as I was about the memory dumps, and I guess I assumed that they were connected to each other.  Perhaps that is not really the case.  Any ideas from anyone about the leaks or the reason using it by another thread makes the browser unavailable for future use?

Thanks. David
I was able to find the memory leaks.  They were afterall my mistake.  I still have the same problem with trying to re-use the open browser, however, after running it from a seperate thread.  Are the com pointers somehow not threadsafe?

Thanks. David
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
jkr,

Sorry for the lack of feedback.  I was hoping for a more comprehensive answer like the one you gave in the sequil to this thread:

https://www.experts-exchange.com/questions/20784141/Using-WebBrowser2-Interface-in-Multithreaded-application.html

Thanks for you help.

David
Thank you!