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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

method executing too many times

Status
Not open for further replies.

mgriffith

MIS
Jul 3, 2001
177
US
i have 2 methods that are using IWebBrowser2 to execute a print method from a com object that is hosted on a webpage. here is the code for the methods:

---------------------------------

STDMETHODIMP CTemplatePrinter::IEPrintNoPrompt(VARIANT varTemplateURL)
{
CComPtr<IOleContainer> spContainer;
CComPtr<IServiceProvider> spSP;
CComPtr<IWebBrowser2> spWB;
CComPtr<IDispatch> spDisp;
CComPtr<IHTMLDocument2> spDoc;
CComPtr<IOleCommandTarget> spCT;
CComVariant vPTPath = varTemplateURL;


m_spClientSite->GetContainer(&spContainer);
spContainer->QueryInterface(IID_IServiceProvider, (void**)&spSP);
spSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser, (void**)&spWB);
spWB->get_Document(&spDisp);
spDisp->QueryInterface(IID_IHTMLDocument2, (void**)&spDoc);
spDoc->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);

// ******* THIS IS WHERE IT'S GOING CRAZY!!!! ******* //
spCT->Exec(&CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, &vPTPath, NULL);

return S_OK;
}


---------------------------------------

STDMETHODIMP CTemplatePrinter::IEPrint(VARIANT varTemplateURL)
{
CComPtr<IOleContainer> spContainer;
CComPtr<IServiceProvider> spSP;
CComPtr<IWebBrowser2> spWB;
CComPtr<IDispatch> spDisp;
CComPtr<IHTMLDocument2> spDoc;
CComPtr<IOleCommandTarget> spCT;
CComVariant vPTPath = varTemplateURL;


m_spClientSite->GetContainer(&spContainer);
spContainer->QueryInterface(IID_IServiceProvider, (void**)&spSP);
spSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser, (void**)&spWB);
spWB->get_Document(&spDisp);
spDisp->QueryInterface(IID_IHTMLDocument2, (void**)&spDoc);
spDoc->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);

// ***** IT CALLS THIS 2 TIMES? ******** //
spCT->Exec(&CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_PROMPTUSER, &vPTPath, NULL);

return S_OK;
}
--------------------------

my question is: does anyone have any idea why the IOleCommandTarget::Exec method it going berzerk? when i call the method from a script, the first one keeps spooling pages into the printer, and the second one opens 2 print dialogs in a row...i also have another function for opening a print preview window that works fine....the only difference is my call to Exec is as follows:
spCT->Exec(&CGID_MSHTML, IDM_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, &vPTPath, NULL);

i've tried all that i can see...if i replace spCT->Exec(...) with
spWB->ExecWB(OLECMD_PRINT, OLECMDEXECOPY_PROMPTUSER, &vPTPath, NULL);
it still does the same thing...i've even tryied without passing in the &vPTPath (printing template path) argument

i also know that the method is only getting called once...i tested this by also using spDoc to write some stuff out to pop up a message box every time it got called, and the message box only came up once, but the printing kept going...

any suggestions?
mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top