/*++ Routine Name: CDocPropPage::DlgProc Routine Description: Dialog proccedure for the property page. This handles all windows messages that are sent to the property page. Arguments: hDlg - Handle of the property page. uiMessage - Specifies the message. wParam - Specifies additional message-specific information. lParam - Specifies additional message-specific information. Return Value: The return value is the result of the message processing and depends on the message sent. --*/ INT_PTR CALLBACK CDocPropPage::DlgProc( _In_ CONST HWND hDlg, _In_ CONST UINT uiMessage, _In_ CONST WPARAM wParam, _In_ CONST LPARAM lParam ) { HRESULT hr = S_OK; BOOL retVal = FALSE; switch (uiMessage) { case WM_INITDIALOG: { // // Store the class instance // PROPSHEETPAGE* pPage = reinterpret_cast<PROPSHEETPAGE*>(lParam); if (SUCCEEDED(hr = CHECK_POINTER(pPage, E_POINTER))) { if (pPage->lParam != NULL) { CDocPropPage* thisInst = reinterpret_cast<CDocPropPage*>(pPage->lParam); if (SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL))) { if (SUCCEEDED(hr = thisInst->StoreThis(hDlg))) { hr = thisInst->SendInit(hDlg); } } } else { hr = E_FAIL; } } // // Set the keyboard focus to the control specified by wParam // retVal = TRUE; } break; case WM_COMMAND: { switch (HIWORD(wParam)) { case EN_CHANGE: case BN_CLICKED: case CBN_SELCHANGE: // case LBN_SELCHANGE: CBN_SELCHANGE=LBN_SELCHANGE { CDocPropPage* thisInst; if (SUCCEEDED(hr = RetrieveThis(hDlg, &thisInst))) { if (SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL))) { hr = thisInst->SendCommand(hDlg, wParam); } } // // Set to FALSE to indiate that the message has been handled. // retVal = FALSE; } break; default: { // // Unhandled command so return TRUE // retVal = TRUE; } break; } } break; case WM_NOTIFY: { NMHDR* pHdr = reinterpret_cast<NMHDR*>(lParam); if (SUCCEEDED(hr = CHECK_POINTER(pHdr, E_POINTER))) { switch (pHdr->code) { case PSN_SETACTIVE: { CDocPropPage* thisInst; if (SUCCEEDED(hr = RetrieveThis(hDlg, &thisInst)) && SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL))) { hr = thisInst->SendSetActive(hDlg); } // // Return FALSE to accept the page activation // retVal = FALSE; } break; case PSN_KILLACTIVE: { // // Return FALSE to allow the page to lose activation // retVal = FALSE; } break; case PSN_APPLY: { PFNCOMPROPSHEET pfnComPropSheet = NULL; CDocPropPage* thisInst; if (SUCCEEDED(hr = RetrieveThis(hDlg, &thisInst)) && SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL)) && SUCCEEDED(hr = thisInst->GetComPropSheetFunc(&pfnComPropSheet)) && SUCCEEDED(hr = CHECK_POINTER(pfnComPropSheet, E_FAIL))) { // // Ensure that the last error is in a known state. // SetLastError(0); // // We do not need to validate any settings so set PSNRET_NOERROR // if (SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR) == 0) { // // A return value of 0 does not necessarily indicate a failure. // hr = HRESULT_FROM_WIN32(GetLastError()); } if (SUCCEEDED(hr)) { // // We have applied the change... // PropSheet_UnChanged(GetParent(hDlg), hDlg); // // Inform the propsheet // pfnComPropSheet(thisInst->GetComPropSheetHandle(), CPSFUNC_SET_RESULT, reinterpret_cast<LPARAM>(thisInst->GetPageHandle()), (LPARAM)CPSUI_OK); } } retVal = TRUE; } break; case UDN_DELTAPOS: { CDocPropPage* thisInst; if (SUCCEEDED(hr = RetrieveThis(hDlg, &thisInst)) && SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL))) { hr = thisInst->SendNotify(hDlg, pHdr); } // // Set return to FALSE to allow the control value // retVal = FALSE; } break; } } } break; case WM_NCDESTROY: { CDocPropPage* thisInst; if (SUCCEEDED(hr = CDocPropPage::RetrieveThis(hDlg, &thisInst)) && SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL))) { hr = thisInst->RemoveThis(hDlg); } // // Set return to FALSE to indicate that the message was processed // retVal = FALSE; } break; } ERR_ON_HR(hr); return retVal; }
/*++ Routine Name: CXDStreamFilter::InitialiseStreamIO Routine Description: This routine initialises the print stream read and write interfaces used by all stream filters Arguments: None Return Value: HRESULT S_OK - On success E_* - On error --*/ HRESULT CXDStreamFilter::InitialiseStreamIO( VOID ) { VERBOSE("Retrieving stream reader and writer.\n"); HRESULT hr = S_OK; // // Make sure the reader and writer are released // m_pStreamReader = NULL; m_pStreamWriter = NULL; if (SUCCEEDED(hr = CHECK_POINTER(m_pInterFltrComm, E_PENDING))) { // // Get the reader and writer from the filter communicator // if (SUCCEEDED(hr = m_pInterFltrComm->RequestReader(reinterpret_cast<VOID**>(&m_pStreamReader)))) { hr = m_pInterFltrComm->RequestWriter(reinterpret_cast<VOID**>(&m_pStreamWriter)); } // // If anything went wrong, make sure the reader and writer // have been released // if (FAILED(hr)) { m_pStreamReader = NULL; m_pStreamWriter = NULL; } } // // Check interface is as expected. If not then it is likely that // the wrong GUID has been defined in the filter configuration file // if (SUCCEEDED(hr)) { CComPtr<IPrintReadStream> pReaderCheck(NULL); CComPtr<IPrintWriteStream> pWriterCheck(NULL); if (FAILED(m_pStreamReader.QueryInterface(&pReaderCheck)) || FAILED(m_pStreamWriter.QueryInterface(&pWriterCheck))) { RIP("Invalid reader and writer defined - check GUIDs in the filter configuration file\n"); // // Request the pipeline manager shutsdown the filter // hr = E_FAIL; RequestShutdown(hr); } } ERR_ON_HR(hr); return hr; }
/*++ Routine Name: CXDSmplUICF::CreateInstance Routine Description: Creates an object of the specified CLSID and retrieves an interface pointer to this object. The supported class objects are currently IPrintOemUI and IPrintOemPrintTicketProvider. Arguments: pUnkOuter - This must be NULL, as aggregare object creation is not supported. riid - The IID of the requested interface. ppvObject - A pointer to the interface pointer identified by riid. If the object does not support this interface, ppvObj is set to NULL. Return Value: HRESULT S_OK - On success E_* - On error --*/ HRESULT CXDSmplUICF::CreateInstance( __in_opt LPUNKNOWN pUnkOuter, __in REFIID riid, __deref_out PVOID* ppvObject ) { HRESULT hr = S_OK; if (ppvObject == NULL) { hr = E_POINTER; goto Exit; } *ppvObject = NULL; if (pUnkOuter == NULL) { // // Create UI component // CXDSmplUI* pXDSmplUI = NULL; try { pXDSmplUI = new CXDSmplUI; hr = CHECK_POINTER(pXDSmplUI, E_OUTOFMEMORY); } catch (CXDException& e) { hr = e; } if (SUCCEEDED(hr)) { // // Get the requested interface // hr = pXDSmplUI->QueryInterface(riid, ppvObject) ; // // Release the IUnknown pointer. If QueryInterface failed // the Release() call will clean up // pXDSmplUI->Release(); // // If QueryInterface failed this could be a request for the // PTProvider Interface // if (FAILED(hr)) { CXDSmplPTProvider* pXDSmplPT = NULL; try { pXDSmplPT = new CXDSmplPTProvider; hr = CHECK_POINTER(pXDSmplPT, E_OUTOFMEMORY); } catch (CXDException& e) { __analysis_assume((*ppvObject) == NULL); hr = e; } if (SUCCEEDED(hr)) { hr = pXDSmplPT->QueryInterface(riid, ppvObject) ; // // Release the IUnknown pointer. // (If QueryInterface failed, component will delete itself.) // pXDSmplPT->Release(); } } } } else { // // Cannot aggregate // hr = CLASS_E_NOAGGREGATION; } Exit: ERR_ON_HR(hr); return hr; }
/*++ Routine Name: CXDStreamFilter::StartOperation Routine Description: This is the stream interface implementation of IPrintPipelineFilter::StartOperation shared by all stream interface filters Arguments: None Return Value: HRESULT S_OK - On success E_* - On error --*/ HRESULT STDMETHODCALLTYPE CXDStreamFilter::StartOperation( VOID ) { VERBOSE("Starting stream filter operation.\n"); HRESULT hr = S_OK; BOOL bDoCoUninitialize = FALSE; if (SUCCEEDED(hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { bDoCoUninitialize = TRUE; } if (SUCCEEDED(hr) && SUCCEEDED(hr = InitialiseStreamIO()) && SUCCEEDED(hr = InitializePrintTicketManager())) { try { CXPSProcessor* pXpsProcessor = new CXPSProcessor(m_pStreamReader, m_pStreamWriter, this, m_pPrintPropertyBag, &m_ptManager); if (SUCCEEDED(hr = CHECK_POINTER(pXpsProcessor, E_OUTOFMEMORY))) { hr = pXpsProcessor->Start(); } if (pXpsProcessor != NULL) { delete pXpsProcessor; pXpsProcessor = NULL; } } catch (CXDException& e) { hr = e; } if (hr == E_NOINTERFACE) { // // The PK archive handler is missing - just pass the data on // if (SUCCEEDED(hr = CHECK_POINTER(m_pStreamReader, E_POINTER)) && SUCCEEDED(hr = CHECK_POINTER(m_pStreamWriter, E_POINTER))) { ULONG cbRead = 0; BOOL bEOF = FALSE; PBYTE pBuff = new BYTE[CB_COPY_BUFFER]; if (SUCCEEDED(hr = CHECK_POINTER(pBuff, E_OUTOFMEMORY))) { do { if (SUCCEEDED(hr = m_pStreamReader->ReadBytes(pBuff, CB_COPY_BUFFER, &cbRead, &bEOF))) { ULONG cbWritten = 0; hr = m_pStreamWriter->WriteBytes(pBuff, cbRead, &cbWritten); } } while (SUCCEEDED(hr) && !bEOF && cbRead > 0); delete[] pBuff; pBuff = NULL; } } } } if (m_pStreamWriter) { m_pStreamWriter->Close(); } // // If the filter failed make sure we shutdown the pipeline // if (FAILED(hr)) { if (m_bFilterFinished) { // // Filter is already closing down so report S_OK // hr = S_OK; } else { // // Request the pipeline manager shutdown the filter // ERR("Requesting filter shutdown\n"); RequestShutdown(hr); } } // // Let the filter pipe manager know the filter is finished // if (bDoCoUninitialize) { CoUninitialize(); } FilterFinished(); ERR_ON_HR(hr); return hr; }