Loading and Displaying the Filter Configuration

Note that the fields on the property page that you will create are based on information extracted from the VendorParametersSets collection associated with the FPCApplicationFilter object. The FPCApplicationFilter object is identified by the filter GUID, and is created when a user accesses the filter node in the Forefront TMG MMC snap-in. When the property page is created, it runs on a separate thread from that of the FPCApplicationFilter object. For this reason, part of the code provided in this example uses marshalling techniques so that pointers can be passed between these two threads.

To load and display the filter configuration

  1. To read the values stored in the vendor parameters sets associated with the filter, add the following function to your project:
    HRESULT GetVendorData(FPCLib::IFPCApplicationFilterPtr spiApplicationFilter,
    				_bstr_t* pbsVirusString,
    				_bstr_t* pbsPrefixString)
    	HRESULT hr = S_OK;
    	FPCLib::IFPCVendorParametersSetsPtr spIFPCVendorParametersSets;
    	FPCLib::IFPCVendorParametersSetPtr spIFPCVendorParametersSet;
    		spIFPCVendorParametersSet = spiApplicationFilter->VendorParametersSets->Item(_bstr_t(PARAM_SET_GUID));
    		*pbsVirusString  = spIFPCVendorParametersSet->Value[_bstr_t("VirusString")];
    		*pbsPrefixString = spIFPCVendorParametersSet->Value[_bstr_t("PrefixString")];
    	catch(_com_error& err)
    		return err.Error();
    	return S_OK;
  2. You need to add code that will call GetVendorData() and display the data retreived on the property page. Create the OnInitDialog method by using the message-handler wizard. Do this in the same way that you create other message handlers: Use the dialog box itself as the control in the Class or object to handle list and the WM_INITDIALOG message as the event. Add the following code to the code generated (m_hWnd serves as a handle to the property page; use it when you need to access any of the controls on the property page):
    	HRESULT hr = S_OK;
    	_bstr_t bsVirusString, bsPrefixString;
    	// Unmarshall an object interface pointer.
    	hr =  CoGetInterfaceAndReleaseStream(
    	// CoGetInterfaceAndReleaseStream releases m_spStreamMarshalApplicationFilter even if it fails.
    	// We set it to NULL so that the destructor doesn't try to release this again.
    	m_spStreamMarshalApplicationFilter.p = NULL;
    	if (FAILED(hr) || !m_spiApplicationFilter.operator bool())
    		return hr;
    	hr = ::GetVendorData(m_spiApplicationFilter, &bsVirusString, &bsPrefixString);
    	if (FAILED (hr))
    		bsVirusString  = "Default Virus String";
    		bsPrefixString = "Default Prefix String";
    	::SetWindowText(::GetDlgItem(m_hWnd, IDC_VIRUS_STRING),  bsVirusString);
    	::SetWindowText(::GetDlgItem(m_hWnd, IDC_PREFIX_STRING), bsPrefixString);
  3. Add an initialization method to the class FilterSnapInPage:
    //This method is used for passing a pointer to the FPCApplicationFilter object of the filter
    HRESULT Initialize(FPCLib::IFPCApplicationFilterPtr DataSource)
    	HRESULT hr = S_OK;
    	hr = CoMarshalInterThreadInterfaceInStream(FPCLib::IID_IFPCApplicationFilter,
    	return hr;
  4. Add the two following private members to the class:
    	FPCLib::IFPCApplicationFilterPtr m_spiApplicationFilter;
    	// Pointer to stream into which this page's IApplicationFilter object interface
    	// pointer will be marshaled.
    	CComPtr<IStream> m_spStreamMarshalApplicationFilter;
  5. Check whether the page was created and initialize the page.
  6. Add the following code to the .cpp file where your snap-in is defined and change the GUID to the GUID of your application filter.
    HRESULT CFilterSnapInExtData::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
    	long handle, 
    	IUnknown* pUnk,
    	HRESULT hr = S_OK;
    	// if (type == CCT_SCOPE || type == CCT_RESULT) 
    	CFilterSnapInPage* pPage = new CFilterSnapInPage(handle, true, _T("FilterSnapIn"));
    	if (bstrGUID == _bstr_t("{7CCF6FF0-D995-4da1-B452-4228047B2D1D}"))  // Filter GUID
    		// Check whether the page was created.
    		if(pPage == NULL)
    			return E_UNEXPECTED;
    		// Initialize the page.
    		if (FAILED(hr = pPage->Initialize(spiApplicationFilter)))
    			return hr;
    		// The second parameter to the property page class constructor
    		// should be true for only one page.
    		// TODO : Add code here to add additional pages
    		return S_OK;
    	return E_UNEXPECTED;

Send comments about this topic to Microsoft

Build date: 11/30/2009

© 2008 Microsoft Corporation. All rights reserved.