Microsoft Internet Security and Acceleration Server 2000

Add the Registration Code

This section describes how to add the registration code to your filter.

To add the registration code

  1. In the Visual C++ Project Settings dialog box, select the C/C++ tab, and from the Category drop-down menu select Preprocessor. In the Additional include directories entry field, add to the include path of the project the appropriate directory for your compilation. This ensures that the compiler can find the msfpccom.tlb file (if the file is not located in a current include directory). Type the same path information in the Additional include directories entry field of the MIDL tab.
  2. In Project Settings, select the C++ tab, and in the C++ Language Category drop-down menu, click Enable Exception Handling, and click OK.
  3. Add the following code to StdAfx.h, before the #include Wspfwext.h directive:
    #import "msfpccom.tlb" rename_namespace("MSFPCCOM") named_guids
    //define the GUID string with your filter GUID value
    #define FILTER_GUID_STRING "{7CCF6FF0-D995-4da1-B452-4228047B2D1D}"
    //define the FILTER_PROTOCOL_GUID
    static const GUID FILTER_PROTOCOL_GUID = { 0x8226e96a, 0xb578, 0x4c28, { 0xb6, 0x86, 0x7e, 0xc9, 0x2b, 0xaf, 0x1e, 0xe7 } }; 
    #define FILTER_PROTOCOL_GUID_STRING "{8226E96A-B578-4c28-B686-7EC92BAF1EE7}"

    In SMTPFltr.cpp, add the following code to your filter registration code:

    // This function is used to register an application filter
    static HRESULT RegisterFWXFilter (BOOL fRegister, FwxScope Scope)
    	HRESULT hr;
    	MSFPCCOM::IFPCFilterProtocolPtr comptrIFPCFilterProtocol;
    	CComPtr<IFWXFilterAdmin> pIFWXFilterAdmin;
    	hr = CoCreateInstance (CLSID_FWXFilterAdmin,
    				(LPVOID *) &pIFWXFilterAdmin);
    	if (FAILED(hr))
    		return hr;
    	if (fRegister)
    		//Strings should be Unicode in this call
    		hr = pIFWXFilterAdmin->
    		InstallFilter (CLSID_SMTPFilter,// GUID
    					L"SMTPFilter",// Name
    					L"Screen SMTP messages",// Description
    					L"Microsoft",// Vendor
    					L"1.0",// Version
    					NULL,//Reserved parameter, must be NULL
    		//OK if already installed.
    			hr = S_OK;
    		if (FAILED(hr))
    			return hr;
    		hr = pIFWXFilterAdmin
    										 L"SMTP server",
    										 L"SMTP inbound via SMTPFLTR",
    										 NULL,//Reserved parameter, must be NULL
    		// Returns OK if already installed.
    			hr = S_OK;
    		if (FAILED(hr))
    			return hr;
    		//Get a pointer to the protocol just registered
    		hr = pIFWXFilterAdmin->GetProtocol(CLSID_SMTPFilter,
    									(struct IFPCFilterProtocol **)&comptrIFPCFilterProtocol);
    		if (FAILED(hr))
    			return hr;
    			//Add primary connection to the protocol just created
    		catch(_com_error& err)
    			//If adding a primary connection to the protocol fails, it is not considered an error
    			if(err.Error() != HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
    				return err.Error();
    		//Unregister protocol
    		hr = pIFWXFilterAdmin->UnregisterProtocolForFilter(CLSID_SMTPFilter,
    		//Unregister filter
    		hr = pIFWXFilterAdmin->UninstallFilter (CLSID_SMTPFilter, Scope);
    	return hr;
    // DllInstall - Application filter installation
    	BOOL bInstall,
    	LPCWSTR pszCmdLine
    	FwxScope Scope;
    	// Must have command line, must be either enterprise or array
    	if (!pszCmdLine) return E_INVALIDARG;
    	if (wcscmp(pszCmdLine, L"enterprise") == 0) {
    		Scope = fwx_EnterpriseScope;
    } else if (wcscmp(pszCmdLine, L"array") == 0) {
    		Scope = fwx_ArrayScope;
    } else {
    		return E_INVALIDARG;
    	return RegisterFWXFilter(bInstall, Scope);
  4. Add the following code to smtpfltr.def:
    DllInstall		@5 PRIVATE
  5. In the implementation of IFWXSessionFilter::FirewallEventHandler in FWXSessionFilter.cpp, add the code shown in bold to set the connection protocol as the filter protocol:
    HRESULT STDMETHODCALLTYPE CFWXSessionFilter::FirewallEventHandler( 
    	/* [out][in] */ const FwxFirewallEvent __RPC_FAR *pFirewallEvent)
    	HRESULT hr = S_OK;
    	IFWXConnection  *piConnection;
    	switch (pFirewallEvent->EventType)
    	// Bind request for TCP sockets
    	case fwx_Bind_Tcp:
    		OutputDebugString ("IFWXSessionFilter::FirewallEventHandler –		fwx_Bind_Tcp\n");
    		OutputDebugString (FilterAccessString(
    		//Get a pointer to the connection
    		//Set the protocol of this connection to be the filter
    		hr = piConnection->SetProtocol(FILTER_PROTOCOL_GUID,0);
    		if (FAILED(hr))
    			OutputDebugString("\tFail to set protocol of connection to  SMTP filter protocol\n");
    			return hr;
  6. Build the project (Rebuild All).

To test the registration and installation code, follow the setup procedures described in Filter Setup, as appropriate for an enterprise or array installation. You will need to reinstall the filter when you complete the filter creation procedure.

Note  Filter objects are created when the Firewall service is loaded, so the service must be restarted when you add a new filter or a new version of an existing filter.