Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Usage of CoGetClassObject, CreateInstance, and relating functions

Status
Not open for further replies.

tonyb007

Programmer
Feb 25, 2004
1
GB
I'm very new to Visual C++ (dropped in at the deepend).

I have a small program that, in simple terms, runs Internet Explorer.

A code snippet that illustrates how it currently works:
Code:
	// Obtain an IWebBrowser2 object
	_bstr_t bstrAppName("InternetExplorer.Application");
	CLSIDFromProgID( bstrAppName, &clsid );

	CoCreateInstance( clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (LPVOID*)&pInterface );

	pInterface->QueryInterface( IID_IWebBrowser2, (LPVOID*)&pBrowser );
	pInterface->Release();
Problem is that if a user runs the exe again, it re-uses the IEXPLORE process (visible in Task Manager) thus sharing the environment already in use - you get another IE window but not the new environment.
I believe from reading up that this seems to be default functionality. However, I need it to create a completely separate, individual Internet Explorer process (so that another IEXPLORE process would appear in Task Manager). To achieve this I believe I need to use something like the following but I don't know enough to make it work:
Code:
IWebBrowser2           *pBrowser   = NULL;
IClassFactory          *pCF = NULL;
IUnknown               *pInterface = NULL;
DWORD                  g_dwRegister;
	
// Obtain an IWebBrowser2 object
_bstr_t bstrAppName("InternetExplorer.Application");
CLSIDFromProgID( bstrAppName, &clsid );

CoGetClassObject( clsid, CLSCTX_LOCAL_SERVER, NULL, IID_IClassFactory, (LPVOID*)&pCF );
CoRegisterClassObject(clsid, (IClassFactory *) pCF, CLSCTX_LOCAL_SERVER, REGCLS_MULTI_SEPARATE, &g_dwRegister );
CoCreateInstance( clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (VOID**)&pBrowser );
pCF->CreateInstance( NULL, IID_IWebBrowser2, (VOID**)&pBrowser );   //added by tb
pCF->Release();
CoRevokeClassObject (g_dwRegister );
Any help would be much appreciated.
T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top