Compiling Forefront TMG 2010 SDK Samples

The Software Development Kit (SDK) for Forefront Threat Management Gateway (TMG) 2010 is available for download from the Microsoft download center here.

We have received a number of questions about issues compiling the SDK samples and wanted to share a few tips with you.

Preparing Your Environment

When compiling the SDK with Visual Studio 2008/2005, the MIDL compiler may fail with the following error:
midl : error MIDL2379 : the compiler reached a limit for a format string representation. See documentation for advice.

To solve this issue, do the following:

a. Verify that Visual Studio 2005/2008 SP1 is installed (you can download VS 2005 SP1 from here and VS 2008 SP1 from here ).

b. Install the updated Windows 7 SDK, which contains a newer version of the MIDL compiler, using the instructions provided in http://blogs.msdn.com/windowssdk/archive/2009/08/07/using-the-win-7-sdk-build-environment-with-vs-2008.aspx

To build the samples for a 64 bit environment, do the following:

1. Make sure you’ve implemented the steps above. Failing to complete these steps will result in a MIDL compiler error on a 64 bit platform.

2. Start Visual Studio 2008.

3. Open the requested sample solution.

4. Complete the conversion wizard (to convert a Visual Studio 6.0 solution to a Visual Studio 2005/2008 solution).

5. By default, the solution targets a 32 bit environment. For Forefront TMG to work with this project you will need to change the target platform to 64 bit. Please follow these steps:

  • Open the Visual Studio Configuration Manager by selecting Build->Configuration Manager.
    image
  • Under “Active solution platform” select the “New…” option. A dialog box will open:
    image
  • Select the new platform as x64. Verify that the other settings (‘Copy settings from’ and ‘Create new project platforms’) are selected the same as in the image above. Click OK, and close the Configuration Manager dialog box.
  • The solution now has the new x64 platform settings in place.
  • Save the solution to finalize this step.
  • Select Project -> Properties from the menu. In the dialog box, expand Configuration Properties, expand Linker and then select General. Make sure the output file settings are .\x64\Debug/WebResponseModifier.dll
    image
  • Select Advanced. Make sure the Target Machine settings are set to Machine X64 (/Machine: X64)
    image
  • Select Command Line. Make sure the Additional Option box is empty and does not include any directive (if you find the ‘/MACHINE:I386’ directive there – remove it).
  • Press OK to finalize changes.

6. You can now build the solution for the x64 bit platform.

Sample specific information

1. Web filters

  • WebExeBlock – When building the sample you may receive the following warning:
    WebExeBlockFilterImpl.cpp
    .\WebExeBlockFilterImpl.cpp(548) : warning C4068: unknown pragma
    You may ignore the warning as it does not influence the code generation and the final outcome.
  • WebResponseModifier – when building the sample you may receive the following link error (for both debug and release configurations):
    1>.\Debug\main.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
    This error happens due to conflicting linker directives. To solve this issue, right-click on the project and select Properties. Under Configuration Properties->Linker->Command Line you will find under Additional options the ‘/MACHINE:I386’ directive. This confuses the compiler because the directive appears twice – once with X64 and once with the I386 option.
    image
    Remove the ‘/MACHINE:I386’ directive, press OK and compile the project again.
    Note: you must do it twice – once for each build configuration (debug or release)

2. Application filters

  • DataMonitor –
    i. When converting the project to Visual Studio 2008 you will get an error in the conversion process. You may ignore it and remove the redundant project (see image below):
    image

    ii. When building the sample you may receive the following compiler error:

    c:\program files (x86)\microsoft forefront tmg tools\sdk\samples\appfilters\datamonitor\admin\stdafx.h(42) : fatal error C1083: Cannot open include file: 'wspfwext.h': No such file or directory

    To fix this issue, right-click on the “DataMonitorAdmin” project and select the Dependencies option. Make sure that the DataMonitor checkbox is checked:
    image
    Clean and rebuild the solution again.

    iii. When building the sample you may receive the following compiler errors:

    1>Performing Custom Build Step
    1>mc : error : 0x2 trying to open file <EventMsgs>.
    1>Project : error PRJ0019: A tool returned an error code from "Performing Custom Build Step"

    This error (in both debug and release configurations) happens due to a missing file extension in a custom build process. To solve this issue, right-click on the file EventMsgs.mc and select the Properties option. The dialog box (shown below) will appear.
    image
    Under Custom Build Step, select Command Line and add the extension ‘.mc’, so it will show the following text: mc $(InputName).mc
    Click OK to close the dialog box and then right-click on the project and select Properties. Under Configuration Properties->Build Events->Post-Build Event, remove the regsvr32 command.
    image
    Press OK and Compile the project.


Support for Large Files

The Web Filters API has been changed so that it supports large files. To declare itself as large-size aware a filter must include the SF_NOTIFY_FLAG_LARGE_SIZE_AWARE flag in the dwFlags field of the HTTP_FILTER_VERSION structure passed to GetFilterVersion() and GetWPXFilterVersion() filter entry points. After setting the flag the filter will get all the regular notifications. The only difference is that the structure passed to the HttpFilterProc() filter entry point for SF_NOTIFY_LOG notification is actually WPX_FILTER_LOG which is an extension of HTTP_FILTER_LOG. The new structure adds two new DWORD fields required for supporting files larger than 4GB: dwBytesSentHigh and dwBytesRecvdHigh.

Author:
Noam Ilovich, Program Manager

Reviewers:
Ori Yosefi, Senior Program Manager
Meir Feinberg, Technical Writer