FBWF API Tutorial Part 1-Build your first FBWF application

FBWF API Tutorial Part 1-Build your first FBWF application

  • Comments 2

This is the first of two tutorials on the FBWF API. This tutorial will go over the steps to create your first FBWF application using Visual Studio. The API can be found at http://msdn2.microsoft.com/en-us/library/aa940917.aspx.

I’ll present just one API in this tutorial focusing more on the setup of your environment to build the application. So let’s begin.

STEP 1: Copy Header and Library

The first thing you need to do is copy the header and library file from the CD.

From the setup.exe program for Windows XP SP2 Feature Pack 2007, click on the FBWF API link. This launches explorer showing two files fbwfapi.h and fbwflib.lib.

Copy these files to your local hard drive say c:\fbwfapi

STEP 2: Create New Win32 Console Application

I called my application Fbwfapp. I also used the defaults to create the project. Make sure to select Visual C++ -> Win32 Console Application

STEP 3: Configure Visual Studio

I’m using Visual Studio 2005 for this example but you should be able to set the same parameters from your build environment.

1. Add c:\fbwfapi directory to your include path.

Project->Properties, Configuration Properties->C/C++->Additional Include Directories (Add path c:\fbwfapi).

2. Add fbwflib.lib file to your dependencies.

Project->Properties, Configuration Properties->Linker->Additional Library Directories (Add c:\fbwfapi).

Project->Properties, Configuration Properties->Linker->Input->Additional Dependencies (Add fbwflib.lib).

3. Disable Isolation.

Project->Properties, Configuration Properties->Linker->Manifest File->Generate Manifest (Choose No)

Project->Properties, Configuration Properties->Linker->Manifest File->Allow Isolation (Choose Don’t allow side-by-side isolation)

4. Use static linkage to reduce dependencies.

Project->Properties, Configuration Properties->General->Use of ATL (Choose Static Link to ATL). NOTE: ATL is not required but using static linkage reduces image dependencies

Project->Properties, Configuration Properties->General->Minimize CRT Use in ATL (Choose Yes)

STEP 4: Modify the source

Add includes fbwf.h and windows.h to the top of your main application.

The only API this application will call is FbwfGetMemoryUsage. This API returns the current cache state.

Here is the complete source code:

// FBWFApp.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <windows.h>
#include "fbwfapi.h"
 
#define ONEKILO              0x400
 
BOOL
APITestMemoryUsage()
{
    ULONG           status;
    FbwfMemoryUsage usage;
 
    status = FbwfGetMemoryUsage(&usage);
    if (status != NO_ERROR) {
        printf( "Error calling FbwfGetMemoryUsage: Error 0x%x\n", status);
              return FALSE;
    } else {
        printf( "CurrentCacheThreshold %d Dir %d File %d NextCacheThreshold %d\n", usage.currCacheThreshold/ONEKILO, usage.dirStructure/ONEKILO, usage.fileData/ONEKILO, usage.nextCacheThreshold/ONEKILO);
              return (TRUE);
    }
}
 
int _tmain(int argc, _TCHAR* argv[])
{
       return APITestMemoryUsage();
}

STEP 5: Compile, Deploy and Run

After compiling the program, you need to copy fbwfapp.exe to the runtime image containing FBWF.

Note: The program will fail to run on your development machine due to missing fbwfdll.dll.

Here is the output:

With this API you can get memory usage by FBWF. dirStructure is memory used by fbwf for general housekeeping of the directory structures. fileData is the memory used for actual file data.

In Part 2, I’ll go into some of the more interesting APIs.

- Milong

Page 1 of 1 (2 items)
Leave a Comment
  • Please add 4 and 1 and type the answer here:
  • Post