Wednesday, April 04, 2007

working with DirectShow

The project I am working on has some code already written using DirectShow and I am working with Visual Studio 2005.

DirectShow needs DirectX also.
So you need both of them installed.
It seems that DirectShow was moved from DirectX and was a separate package. Now it seems it is part of the Windows Platform SDK.

Latest "DirectX Software Development Kit" location here

Latest Platform SDK it is called "Microsoft Windows Server 2003 R2 Platform SDK" and get it from here
From the webpage select the type of target platform you want the SDK for.
It will download a small web installer from which you can select what SDK components you want to download an install. In this case choose DirectShow.

The project uses a DirectShow filter and this one needs Strmbase.lib which is the static library from BaseClasses (located under: (SDK root)\Samples\C++\DirectShow\BaseClasses)
The documentation says that there it should be an BaseClasses.dsw file but its not.
I did a search on google on this file and i found this as a response to someone with the same problem:
"There are no project files in the Platform SDK. You must build from command line using the appropriate build shortcut under the Platform SDK menu item.

Once launched, use the DOS CD command to change to the Baseclasses directory and type NMAKE.

You can also get just the project files from an older distribution here:

http://tmhare.mvps.org/downloads.htm"

So I downloaded "DirectShow SDK Project Files (version 0.2 for W2K3 R2 PSDK) 146 KB." from that location which has the sln and vcproj files to build BaseClasses.

Also, when building DirectShow applications make sure that:

in Visual Studio VC++ Directories Options you have at the top both in Include and Libs the path to the Include and Lib folders of DirectShow and DirectX.

if the application (for example a filter) uses environment variables to locate the DirectShow include \ library files (like $(DSHOWBASECLASSES)\.,$(DXSDK)\include) then make sure you have or define else these variables.
$(DSHOWBASECLASSES) must point to the (SDK root)\Samples\C++\DirectShow\BaseClasses
where (SDK Root) is the root folder installation of DirectShow (the application (filter) needs the path to locate strmbas.lib file (the BaseClasses lib))

$(DXSDK) is the root folder of the DirectX installation.

If while compiling you get this error:
error C1189: Need to include strsafe.h after tchar.h

A possible explanation is done here: http://harshdeep.wordpress.com/2006/05/30/directshow-with-visual-studio-8/
(he tried to compile by hand the BaseClasses and link to it in his application and he got different errors)

"The first step was to get the latest DirectShow SDK - as I mentioned in the last post, it’s a part of the Platform SDK and Direct X SDK is required to build the samples. The first sample, Baseclasses, is what I needed. I built the static libraries strmbasd.lib (debug) and strmbase.lib (release) through nmake, as DirectShow documentation suggested, and linked them to the corresponding builds of my dll that uses DirectShow. This opened up a Pandora’s box of compiler, linker and run-time errors.

tchar.h was throwing a compiler error - “error C1189: Need to include strsafe.h after tchar.h”. Lots of people have complained about this error in the forums. dshow.h includes strsafe.h, so in this case the error simply reads “include tchar.h before including dshow.h”.

I was getting some “undefined symbols” link errors for functions that I could clearly see in Baseclasses code. It was because I’d used nmake to build the libraries. The default settings that it used were not compatible with the project settings of my DirectShow code.

I created a VS8 project for Baseclasses. All I had to do to fix the link errors was to match the “Character Set” and “Treat wchar_t as a Built-in type” settings in the project properties of Baseclasses and my dll that links to it. But this code was still crashing. Reason - different “Structure alignment” in the two projects. Using the same value in both the projects fixed it.

Moral of the story: Don’t use nmake to build Baseclasses for you - write a VS project and use the right settings.
"

No comments:

Post a Comment