Build a Filter or Application with Visual C++ 5.x


This article describes step-by-step procedures for building your Microsoft® DirectShow™ projects. You can either build your filter or application from the command line, or build it from within the Visual Studio environment that comes with Microsoft Visual C++®. If you choose to build a filter from within Microsoft Visual Studio™, you can use the VC5Kit set of files shipped with the DirectShow SDK, by default, in the dxmedia\tools\VC5Kit directory. This provides an easy way to configure Visual Studio project settings. You can also set the project settings within Visual Studio yourself.

The main difference between building a filter and building an application from within Visual Studio is that for a filter you select Win32 Dynamic-Link Library as the project type, while for an application you select Win32 Application or Win32 Console Application as the project type. (You choose the project type in the New Projects dialog box opened by choosing the New command from the File menu.)

This article includes the following topics.

Building a Filter or Application from the Command Line

Perform the following steps to build a DirectShow project from the command line.

  1. Go to the Visual C++ Bin directory.
  2. Type VCVARS32.
  3. Go to the directory containing the filter you want to build.
  4. If you are building a sample filter and the sample filter isn't in the default directory (the default is \dxmedia\Samples\ds\Samplename; for example, \dxmedia\Samples\ds\Gargle), set the AXSDK MAKEFILE variable to the top-level DirectShow directory. For example, at the command prompt, type:
    
    set axsdk=c:\dxmedia
    
  5. At the command prompt, type:
    NMAKE
    

    For nondebug versions, type:

    NMAKE NODEBUG=1
    

Using VC5Kit to Build a Filter in Visual Studio

This section discusses building filters with Microsoft® Visual C++® version 5.x. The 5.x VC5Kit is installed by default in the dxmedia\tools\VC5Kit directory.

Setting the Visual Studio Include and Lib Directories

This topic describes how to set your Visual Studio Include and Lib directories. If you are building a DirectShow sample application, such as PlayFile, that comes with a makefile or .mak file, the steps in this topic are the only ones you must perform to build the sample. Once you set your directories, you can choose Open Workspace from the File menu and select the existing makefile or .mak file. Visual Studio will wrap the makefile. If you are building a filter, other steps will probably be necessary.

  1. Open Visual Studio.
  2. From the Tools menu, choose Options.
  3. Choose the Directories tab.
  4. In the Show directories for drop-down list, select Include files.
  5. Add the DirectShow include directories (by default: dxmedia\Include and dxmedia\Classes\Base) to the list.
  6. In the Show directories for drop-down list, select Library files.
  7. Add the DirectShow library directory (by default C:\dxmedia\Lib).

Creating a Project Directory and Adding Source Files

Follow these steps to create your project directory and add your source files to it:

  1. Create an empty directory for your project; for example, C:\Filter.
  2. Copy the VC5Kit Filter.def, Filter.dsp, Filter.dsw, and Filter.mak files into the directory.
  3. Copy your source files into the directory. This includes .h, .cpp and any other miscellaneous source files your project requires. If your project has its own .def and .rc files, you can use these rather than the .def and .rc files provided with VC5Kit.

Building the Project in Visual Studio

Follow these steps to build your project in Visual Studio:

  1. From the File menu in Visual Studio, choose Open Workspace.
  2. In the Open Workspace dialog box that appears, browse to the directory you created and select Filter.dsw.

    The project opens.

  3. To add your source files to the project, choose Add to Project from the Project menu, and then choose Files from the submenu that appears. Browse to the directory containing your source files, select the ones you want to add, and click the OK button.
  4. From the Project menu, choose Settings.
  5. Choose the Link tab and select General from the Category drop-down list.
  6. In the Output file name box, type the name of your filter; for example, Filter.ax.
  7. Choose OK to confirm the project settings you've selected.
  8. Choose Build Filter.ax from the Build menu. The name Filter.ax is the name you gave the output file in the Link tab.

Creating a GUID

If you are building your filter using source files from an existing filter, including any samples filter that ships with DirectShow, you must create a GUID for the new filter.

To create a GUID in Visual Studio:

  1. From the Tools menu, choose Create GUID. By default, the GUID is in DEFINE_GUID format, which is the format you want.
  2. Click the Copy button.
  3. Delete the old GUID from your source file.
  4. Put the cursor in your source file where the old GUID used to be, and choose Paste from the Edit menu.

Creating a Definition File

If your filter implements the DllGetClassObject, DllCanUnloadNow, DllRegisterServer, or DllUnregisterServer functions, you must include a definition file (.def file) that exports them. For example (where Filter.ax is the name you gave the output file):


LIBRARY FILTER.AX
DESCRIPTION 'Description of my filter'
PROTMODE
EXPORTS 
    DllGetClassObject  
    DllCanUnloadNow  
    DllRegisterServer  
    DllUnregisterServer 

Setting DirectShow Project Settings in Visual Studio

This section describes how to set project settings in Visual Studio to build your own DirectShow applications and filters. If you are building samples supplied by DirectShow, you need only set your Include and Lib directories.

In some cases, you might need to add to these project settings for your particular application. For example, if you use DirectDraw functions, you must add Ddraw.lib to the list of Link libraries.

In all cases, you must set the Visual Studio Include and Lib directories as described in Setting the Visual Studio Include and Lib Directories.

This section contains the following topics.

Creating a Project

To create a project, perform the following steps.

  1. From the File menu, choose New.
  2. Choose the Projects tab.
  3. If you are building an application, select Win32 Application as the type of project. If you are building a filter, select Win32 Dynamic-Link Library.
  4. Type a name for the project and a location for the project files.

Adding Files to the Project

To add files to the project, perform the following steps.

  1. From the Project menu, choose Add to Project. From the submenu that appears, choose Files.
  2. In the Insert Files into Project dialog box that appears, browse for the filter files you want to add to the project, such as the .cpp, .h, .rc, and .def files.
  3. Select the file or files you want to add and choose OK.

Setting Project Settings For Both Release and Debug Builds

To set project settings for both release and debug builds, perform the following steps.

  1. From the Project menu, choose Settings.
  2. In the dialog box that appears, select All Configurations in the Settings For drop-down list.

Follow these steps to set your project general settings:

  1. From the Project menu, choose Settings.
  2. Choose the General tab.
  3. From the Microsoft Foundation Classes drop-down list, select Not Using MFC.

Follow these steps to set your project compiler settings:

  1. From the Project menu, choose Settings.
  2. Choose the C/C++ tab.
  3. In the Category drop-down list, select General.
  4. In the Preprocessor definitions text box, insert the following:
    INC_OLE2,STRICT,WIN32,_MT,_DLL,_X86_=1,WINVER=0x0400
  5. Select the C++ Language category.
  6. Select the Enable exception handling check box.
  7. Choose the Code Generation category.
  8. In the Processor drop-down list, select Blend*.
  9. In the Calling convention drop-down list, select _stdcall.
  10. In the Use Run-time library drop-down list, select Multithreaded DLL.
  11. Select the Precompiled Headers category.
  12. Select the Not using precompiled headers option button.

Follow these steps to set your project link settings:

  1. From the Project menu, choose Settings.
  2. Choose the Link tab.
  3. In the Category drop-down list, select General.
  4. In the Output file name text box, type the filter's output file name; for example, Debug/Filter.ax.
  5. Add the following libraries to the beginning of the Object/Library modules text box.
    quartz.lib strmbase.lib msvcrt.lib

    These libraries must be the first libraries in the link list. Depending on the functions your application accesses, you might need to add other libraries to this list.

  6. Select the Ignore all default libraries check box.
  7. Select the Customize category.
  8. Clear the Use program database check box.
  9. Select the Output category.
  10. In the Base address text box, type:
    0x1c400000
    
  11. In the Entry-point symbol text box, type:
    DllEntryPoint@12
    

Setting Project Settings for Debug Builds

To set project settings for debug builds, perform the following steps.

  1. From the Project menu, choose Settings.
  2. Select Win32 Debug in the Settings For drop-down list in the Project Settings dialog box that appears.
  3. Choose the C/C++ tab.
  4. In the Category drop-down list, select General.
  5. Select the Generate browse info check box.
  6. In the Debug info drop-down list, select C7 Compatible.
  7. Select the Code Generation category.
  8. In the Use Run-time library drop-down list, select Debug Multithreaded DLL.
  9. Choose the Link tab.
  10. Select the Debug category.
  11. Select the Debug info check box.

Building a Release or Debug Version of Your Project

To build a release or debug version of your project:

  1. Choose Set Active Configuration from the Build menu, and select Win32 Release or Win32 Debug from the list that appears.
  2. Choose Build Filter.ax from the Build menu. The name Filter.ax is the name you gave the output file in the Link tab.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.