Compiling Forefront TMG 2010 SDK Samples

Compiling Forefront TMG 2010 SDK Samples

  • Comments 5
  • Likes

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

Comments
  • I compile WebResponseModifier sample from latest forefront SDK. After registration(regsvr32) this filter and restarting fwsrv service i have this message in

    application event log:

    Warning 07.05.2010 16:52:03 Microsoft Forefront TMG Web Proxy 31505 None

    The Web filter C:\Program Files\Microsoft Forefront Threat Management Gateway\\WebResponseModifier.dll cannot process content that is larger than 4 gigabytes. Web content larger than 4 gigabytes that is sent to this Web filter for processing will be blocked. To resolve the issue, either disable this Web filter or upgrade it to a version that supports Web content larger than 4 gigabytes.

    xml date:

    Log Name:      Application

    Source:        Microsoft Forefront TMG Web Proxy

    Date:          07.05.2010 16:52:03

    Event ID:      31505

    Task Category: None

    Level:         Warning

    Keywords:      Classic

    User:          N/A

    Computer:      TMG1

    Description:

    The Web filter C:\Program Files\Microsoft Forefront Threat Management Gateway\\WebResponseModifier.dll cannot process content that is larger than 4 gigabytes. Web content larger than 4 gigabytes that is sent to this Web filter for processing will be blocked. To resolve the issue, either disable this Web filter or upgrade it to a version that supports Web content larger than 4 gigabytes.

    Event Xml:

    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">

     <System>

       <Provider Name="Microsoft Forefront TMG Web Proxy" />

       <EventID Qualifiers="32768">31505</EventID>

       <Level>3</Level>

       <Task>0</Task>

       <Keywords>0x80000000000000</Keywords>

       <TimeCreated SystemTime="2010-05-07T12:52:03.000000000Z" />

       <EventRecordID>7208</EventRecordID>

       <Channel>Application</Channel>

       <Computer>TMG1</Computer>

       <Security />

     </System>

     <EventData>

       <Data>C:\Program Files\Microsoft Forefront Threat Management Gateway\\WebResponseModifier.dll</Data>

     </EventData>

    </Event>

    I use: Visual Studio Standart 2008 sp1,Windows 7 SDK. Project settings as described above (x64 platfom, linker settings - MachineX64 (/MACHINE:X64)).

  • guys can you please explain what's going on? we have same issue like "web filter cannot process content that is larger than 4 gigabytes" with our own plugin and webresponsemodifier sample from forefront SDK.

  • Thanks for the comments - we've updated the blog entry to describe large file support.

  • I try to compile "Socks5" and I'am confronted to a problem :

    I compile in x64 and i obtain a dll file.

    I put the dll file into the "C:\Program Files\Microsoft Forefront Threat Management Gateway" directory and after i enter the command regsvr32 "C:\Program Files\Microsoft Forefront Threat Management Gateway\socksfltr.dll"

    The plugin didn't display into "Application Filters".

    What I Do wrong ?

  • It is good for me now, i response on social.technet.microsoft.com/.../a64935fd-6e82-4cb2-adc5-e1b20eb8ba51

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment