Microsoft Internet Security and Acceleration Server 2000

Implement the IFWXFilter::AttachToSession Method

The Firewall service calls the IFWXFilter::AttachToSession method when a registered event of the filter occurs (as defined in FilterInit). The COM method CComObject<>::CreateInstance is similar to the CoCreateInstance function, but only creates an instance of the class (with a reference count equal to 0) and does not need a GUID to do so. Add the following code to SMTPFilter.cpp, in place of the simple implementation you inserted earlier:

HRESULT STDMETHODCALLTYPE CSMTPFilter::AttachToSession( 
	/* [in]  */ IFWXSession __RPC_FAR *piSession,
	/* [out] */ IFWXSessionFilter __RPC_FAR *__RPC_FAR *piSessionFilter,
	/* [out] */ PFwxFilterHookEvents __RPC_FAR *ppFilterHookEvents)
{
	OutputDebugString ("FWXFilter::AttachToSession\n");

	HRESULT hr = S_OK;
 
	CComObject<CFWXSessionFilter> *pSessionFilter;
	CComPtr<IFWXSessionFilter> spIFWXSessionFilter;
 
	//Create an instance of the session filter
	hr = CComObject<CFWXSessionFilter>::CreateInstance (&pSessionFilter);
	if (FAILED(hr))
		return hr;
 
	pSessionFilter->AddRef();
 
	hr = pSessionFilter->QueryInterface(IID_IFWXSessionFilter,
									 reinterpret_cast<void**>(&spIFWXSessionFilter));
	pSessionFilter->Release();
 
	if(SUCCEEDED(hr))
	{ 
		//Define new set of events
		m_FwxPortRangeEvents.dwSocketEvents=FWX_ALL_SOURCES
										 | fwx_AcceptedConnection
										 | fwx_Bind_Tcp;
 
		hr = m_pIFWXFirewall->DuplicateFilterHookEvents (&m_FwxFilterHookEvents,
													 ppFilterHookEvents);
}
	if (FAILED(hr))
		return hr;
 
	*piSessionFilter = spIFWXSessionFilter.Detach();
	return hr;
}

Add to smtpfilter.cpp the following include statement:

#include "FWXSessionFilter.h"