Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

CoCreateInstance() on Internet Explorer is unsuccessful after multiple calls


View products that this article applies to.

Symptoms

If you try to call CoCreateInstance() with a CLSID of CLSID_InternetExplorer multiple times, you eventually see CoCreateInstance() return seemingly random failure HRESULTs, including E_NOINTERFACE and E_CLASS_NOT_REG. You may also see strange windowing behavior through the operating system; for example, the All Programs window on the Start menu does not open when you select it.

This problem is most relevant to applications that automate Internet Explorer and that require multiple instances of the browser to run at one time, such as load-testing applications.

↑ Back to the top


Cause

Microsoft Windows maintains a kernel structure that is known as the desktop heap. Every new instance of a Windows executable (.exe) file has a window station and a desktop structure that is allocated for the instance out of this heap. By default, the total heap that is available for interactive applications is about three megabytes (MB). This limits the number of running instances of Internet Explorer to between 60 and 70.

Note Interactive applications are applications that have a message pump and that accept user input.

↑ Back to the top


Resolution

For more information about how to increase the memory that is available for the interactive desktop heap, click the following article number to view the article in the Microsoft Knowledge Base:
126962 "Out of Memory" error message appears when you have a large number of programs running
On Microsoft Windows 2000 and Microsoft Windows XP, the SharedSection variable that is discussed in this article has an array of three numbers; you must change the second number, which is the interactive desktop heap. However, keep in mind that increasing this value may result in serious performance degradation on your computer.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

Steps to reproduce the behavior

  1. In Microsoft Visual C++ 6.0 or 7.0, create a Windows Console application.
  2. Add code to main() to initialize COM and open multiple instances of Internet Explorer by using CoCreateInstance():
         CoInitialize(NULL);
    
         while ( !FAILED(hr = CoCreateInstance(CLSID_InternetExplorer,
    
          NULL, CLSCTX_SERVER, IID_IWebBrowser2,
    
            (LPVOID*)&(curBrowser)))) {
    
                 Sleep(delay);
    
                 curBrowser->Stop();
    
                 //curBrowser->Release();
    
         }
    
         CoUninitialize();
    					
    If you comment out the "curBrowser->Release();" line, you do not see a problem because each instance of Internet Explorer is recycled immediately after creation. If you try to keep these instances running, however, you will notice that the inside of the while block does not execute after about 60 iterations.

↑ Back to the top


References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Keywords: KB323568, kbprb

↑ Back to the top

Article Info
Article ID : 323568
Revision : 5
Created on : 5/15/2006
Published on : 5/15/2006
Exists online : False
Views : 543