Microsoft KB Archive/323568

= CoCreateInstance on Internet Explorer is unsuccessful after multiple calls =

Article ID: 323568

Article Last Modified on 5/15/2006

-

APPLIES TO


 * Microsoft Internet Explorer 6.0
 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q323568



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.



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.



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 &quot;Out of Memory&quot; 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.



STATUS
This behavior is by design.



Steps to reproduce the behavior
 In Microsoft Visual C++ 6.0 or 7.0, create a Windows Console application.  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 &quot;curBrowser->Release;&quot; 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. 

