Tuesday, May 13, 2008

Compile DirectX 9 SDK samples and BaseClasses under Visual Studio 2005

I have noticed that there are a lot of complaints about building DX9 projects especially the BaseClasses under example code directory using Visual Studio 2005. I personally also experienced the similar errors. I had a project that compiled perfectly under my DX9 + Visual Studio 2003 (VS7). When I imported the project to my Visual Studio 2005 environment, I suddenly got many compilation errors. After spending some time debugging and searching information from Internet, I finally fixed all those issues. The errors might appear as follows:

…\DirectShow\Samples\C++\DirectShow\BaseClasses\ctlutil.h(278) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Or


c:\program files\microsoft visual studio 8\vc\platformsdk\include\winnt.h(222) : error C2146: syntax error : missing ';' before identifier 'PVOID64'


Anyway, to my understanding, the above problems have several root causes. First, the include files are messed up when importing the DX9 projects under VS2005. Note that in VS2005 there are two places where you configure the include directories. The first one is when you right click the project properties and select “Configuration Properties” and then choose C/C++ -> general ->Additional Include directories. The other place to add include directories is to use “Tools ->Options ->Project and Solutions ->VC++ directories ->select include files from the top-right list box”. Note that project include directories will overwrite the tools-options include directories. In my platform, my DX9 is installed under C:\DXSDK\ and my VS2005 is installed under “Program Files” on C drive.


My project include directories are configured as:

  • “.,..\..\..\..\include”

My tools options include directories are configured as:

  • $(VCInstallDir)include
  • $(VCInstallDir)PlatformSDK\include
  • $(VCInstallDir)atlmfc\include
  • $(FrameworkSDKDir)include
  • C:\DXSDK\Include
  • C:\DXSDK\Samples\C++\DirectShow\BaseClasses


Note that the above include order is very important because the project needs to include platform SDK include files first and then DX’s own include files.

There will be some errors even using the above correct include order. For example, the compiler might complain that the “PVOID64” definition has problems. The fix for that issue is to add the following line at line 220 in winnt.h file.

#define POINTER_64 __ptr64


There will be other errors such as “g_dwLastRefresh” does not have a type, or “Count” is not defined, etc. These are can be easily fixed by just adding data type definitions. The fix for ctlutil.h file is to change the following code from:

operator=(LONG);

to

COARefTime& operator=(LONG);

After these minor fixes, the BaseClasses under VS2005 should compile OK.

Saturday, May 03, 2008

compile ffdshow

The ffdshow trunk I downloaded is version 20071127. It seems that another ffdshow project called “ffdshow tryout” has been forked from the original ffdshow project on SourceForge and this new project is more active and new developers probably should check this out first before downloading the latest SVN build from the main ffdshow project.

It has also been discussed (can't remember it is from AVSforum or Doom9) that the project is no longer supported on VC6, so I have to upgrade my VC to Visual Studio 2005. Also note that DirectX 9 SDK is required to compile the project. Some codes have been hand written in assembly language for better performance. That can be either compiled by NASM or YASM. The latter is basically a rewrite of the former but under BSD license. Those two assemblers should be placed under Visual Studio installation directory and under “VC\bin” directory then VS2005 can find them during building. Note that the rule files are included in the checked out source files and they also need to be copied to “VC\VCProjectDefaults” directories. That way, when we right click the project, we can then choose “Custom Build Rules” to edit the options. For example, you should remove –DHAVE_SSE3 or some other options if that is not supported by your CPU. The options I have been using are:

nasm –f win32 –DPREFIX –DWIN32 –I$(InputDir) –o $(IntDir)\$(InputName).obj $(InputPath)

That should work on most platforms but the performance may not be the best because some SSE based optimization is not being used.


When compiling the project, I saw some errors and it appeared that nasm complained about those 64-bit operands used in file cpuid64.asm. I just right clicked it and excluded it from the project since I am not working on a 64-bit platform. Then, the whole project compiled and I got a DirectShow filter called ffdshow.ax. A DirectShow filter is a COM object and we will need register it first before using it.


The project already contains a batch file called register.bat, but it basically just uses the following command to do the job:

regsvr32 ffdshow.ax