[1] 请确保您的机子上已经安装了VS 2005和DirectX 9.0b SDK。DX9.0 SDK的下载地址就不写了,自己在网上找吧!(我的DX9.0安装在D盘根目录下)
[2] 首先编译SamplesC++DirectShowBaseClasses目录下的baseclasses.sln以得到两个库文件(strbase.lib和strmbase.lib)。以下介绍的主要是如何修改编译中的错误,这也是众多文章中没有叙述的部分。自己写的,有些啰嗦,请原谅哦!
进入DirectShow的安装目录,找到SamplesC++DirectShowBaseClasses,双击baseclasses.sln打开该解决方案。首先看到的会是Visual Studio的转换向导,不用管它,直接Next到Finish。
点击F5,调试运行,你会见到下面的错误(至少我编译的时候就是这样的结果):
1>------ Build started: Project: BaseClasses, Configuration: Debug Unicode Win32 ------
1>Compiling...
1>dllentry.cpp
1>D:Program FilesMicrosoft Visual Studio 8VCPlatformSDKincludewinnt.h(222) : error C2146: syntax error : missing ';' before identifier 'PVOID64'
1>D:Program FilesMicrosoft Visual Studio 8VCPlatformSDKincludewinnt.h(222) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:Program FilesMicrosoft Visual Studio 8VCPlatformSDKincludewinnt.h(5940) : error C2146: syntax error : missing ';' before identifier 'Buffer'
1>D:Program FilesMicrosoft Visual Studio 8VCPlatformSDKincludewinnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:Program FilesMicrosoft Visual Studio 8VCPlatformSDKincludewinnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:DXSDKSamplesC++DirectShowBaseClassesctlutil.h(278) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:DXSDKincludeuuids.h : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
1>Build log was saved at "file://d:DXSDKSamplesC++DirectShowBaseClassesDebug_UnicodeBuildLog.htm"
1>BaseClasses - 6 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
没办法,改错。(网上老外的文章中说过,不过也不明白什么意思!)
双击1>D:Program FilesMicrosoft Visual Studio 8VCPlatformSDKincludewinnt.h(222) : error C2146: syntax error : missing ';' before identifier 'PVOID64' 跳转到出错的位置。
你会见到错误语句:typedef void * POINTER_64 PVOID64;
这样的定义,VS2005中是不支持的。将其修改为两条语句:
#define POINTER_64 __ptr64
typedef void *PVOID;
typedef void *POINTER_64 PVOID64;
然后调试运行,会发现还有1条错误:
1>------ Build started: Project: BaseClasses, Configuration: Debug Unicode Win32 ------
1>Compiling...
1>dllentry.cpp
1>d:DXSDKSamplesC++DirectShowBaseClassesctlutil.h(278) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:DXSDKincludeuuids.h : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
1>Build log was saved at "file://d:DXSDKSamplesC++DirectShowBaseClassesDebug_UnicodeBuildLog.htm"
1>BaseClasses - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
只有继续改啦!双击1>d:DXSDKSamplesC++DirectShowBaseClassesctlutil.h(278) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 跳转到出错的位置。
你会见到错误语句:operator=(LONG);
只是没有返回值嘛!给它加一个就行了,将其改为:LONG operator=(LONG);
再次调试运行,哇塞!更多错误:
1>------ Build started: Project: BaseClasses, Configuration: Debug Unicode Win32 ------
1>Compiling...
1>wxdebug.cpp
1>.wxdebug.cpp(534) : warning C4996: '_vsnwprintf' was declared deprecated
1> D:Program FilesMicrosoft Visual Studio 8VCincludestdio.h(450) : see declaration of '_vsnwprintf'
1> Message: 'This function or variable may be unsafe. Consider using _vsnwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See _disibledevent="file:///d:DXSDKSamplesC++DirectShowBaseClassesDebug_UnicodeBuildLog.htm">file://d:DXSDKSamplesC++DirectShowBaseClassesDebug_UnicodeBuildLog.htm"
1>BaseClasses - 10 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
有错就改啦!双击1>.wxdebug.cpp(567) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 跳到出错位置。
你会见到出错语句:static g_dwLastRefresh = 0;
静态类型变量有这么定义的吗?总得给个类型吧!将其改为:static DWORD g_dwLastRefresh = 0;为什么类型指定为DWORD?看程序中的语句就明白了——保证相同类型的变量进行运算。
再次调试运行:
1>------ Build started: Project: BaseClasses, Configuration: Debug Unicode Win32 ------
1>Compiling...
1>winutil.cpp
1>.winutil.cpp(2104) : error C2065: 'Count' : undeclared identifier
1>.winutil.cpp(2106) : error C2228: left of '.peRed' must have class/struct/union
1>.winutil.cpp(2106) : error C2228: left of '.peRed' must have class/struct/union
1>.winutil.cpp(2107) : error C2228: left of '.peGreen' must have class/struct/union
1>.winutil.cpp(2107) : error C2228: left of '.peGreen' must have class/struct/union
1>.winutil.cpp(2108) : error C2228: left of '.peBlue' must have class/struct/union
1>.winutil.cpp(2108) : error C2228: left of '.peBlue' must have class/struct/union
1>.winutil.cpp(2124) : error C2228: left of '.peFlags' must have class/struct/union
1>outputq.cpp
1>.outputq.cpp(664) : error C2065: 'iDone' : undeclared identifier
1>Generating Code...
1>Build log was saved at "file://d:DXSDKSamplesC++DirectShowBaseClassesDebug_UnicodeBuildLog.htm"
1>BaseClasses - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
错误少了一个哦!继续努力!双击1>.winutil.cpp(2104) : error C2065: 'Count' : undeclared identifier跳到出错位置。
你会见到出错语句:for (Count = 0;Count < Result;Count++) {
Count没有定义?看该语句上面的语句:
for (UINT Count = 0;Count < Result;Count++) {
if (SystemEntries[Count].peRed != pEntry[Count].peRed ||
SystemEntries[Count].peGreen != pEntry[Count].peGreen ||
SystemEntries[Count].peBlue != pEntry[Count].peBlue) {
bIdentityPalette = FALSE;
}
}
// And likewise compare against the last ten entries
Result = GetSystemPaletteEntries(hdc,PalHiStart,PalLoCount,SystemEntries);
看到了吧!Count是在循环体内定义的变量,出了循环之后就“生命”over了。所以将它定义到外面去。将以上的语句改为:
UINT Count = 0;
for (Count = 0;Count < Result;Count++) {
if (SystemEntries[Count].peRed != pEntry[Count].peRed ||
SystemEntries[Count].peGreen != pEntry[Count].peGreen ||
SystemEntries[Count].peBlue != pEntry[Count].peBlue) {
bIdentityPalette = FALSE;
}
}
// And likewise compare against the last ten entries
Result = GetSystemPaletteEntries(hdc,PalHiStart,PalLoCount,SystemEntries);
再次调试运行:
1>------ Build started: Project: BaseClasses, Configuration: Debug Unicode Win32 ------
1>Compiling...
1>winutil.cpp
1>outputq.cpp
1>.outputq.cpp(664) : error C2065: 'iDone' : undeclared identifier
1>Generating Code...
1>Build log was saved at "file://d:DXSDKSamplesC++DirectShowBaseClassesDebug_UnicodeBuildLog.htm"
1>BaseClasses - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
不错哦!错误剩下一个了!再改,双击1>.outputq.cpp(664) : error C2065: 'iDone' : undeclared identifier
跳到出错位置。
你会见到出错语句:*nSamplesProcessed = iDone - iLost;
iDone没有定义?OK,继续看它上面的语句:
// Loop processing the samples in batches
LONG iLost = 0;
for (long iDone = 0;
iDone < nSamples || (m_nBatched != 0 && m_bSendAnyway);
) {
// ...
同样的,将iDone的定义放到循环体的外面去,改为:
// Loop processing the samples in batches
LONG iLost = 0;
long iDone = 0;
for (iDone = 0;
iDone < nSamples || (m_nBatched != 0 && m_bSendAnyway);
) {
// ...
改完了以后,再次调试运行:
1>------ Build started: Project: BaseClasses, Configuration: Debug Unicode Win32 ------
1>Compiling...
1>outputq.cpp
1>Creating library...
1>Build log was saved at "file://d:DXSDKSamplesC++DirectShowBaseClassesDebug_UnicodeBuildLog.htm"
1>BaseClasses - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
总算见到succeeded了,呵呵!你调出来了吗?
接着,生成所需要的那几个库文件,步骤如下:
单击VS2005菜单栏中的Build-->Batch Build-->单击弹出的Batch Build对话框中的Select All按钮-->单击Build按钮。生成我们编程所需要的那两个库文件:strbase.lib和strmbase.lib。
[3] 将DirectX SDK的Include和Lib目录配置到VS2005的系统目录中去,并且放在标准的VS2005目录之前。步骤如下:
单击VS2005菜单栏上的Option(选项)-->单击弹出的Option对话框中Projects and Solutions前的加号将其展开-->单击VC++ Directories-->
(1) 在show directories for下拉列表中选中Include files,然后添加下列路径:
D:DXSDKInclude
D:DXSDKSAMPLESC++DIRECTSHOWBASECLASSES
D:DXSDKSAMPLESC++COMMONINCLUDE
(2) 在show directories for下拉列表中选中library files,然后添加下列路径:
D:DXSDKLib
D:DXSDKSamplesC++DirectShowBaseClassesDebug
D:DXSDKSamplesC++DirectShowBaseClassesDebug_Unicode
D:DXSDKSamplesC++DirectShowBaseClassesRelease
D:DXSDKSamplesC++DirectShowBaseClassesRelease_Unicode
路径添加完成以后,别忘了点确定哦!
[4] 这一步只是简单的介绍一下编程时需要附加什么样的库文件及如何添加。
DirectShow应用程序应该至少连接库文件strmiids.lib和quartz.lib。前者定义了DirectShow标准的CLSID和IID,后者定义了导出函数AMGetErrorText(如果应用程序中没有使用到这个函数,也可以不连接这个库)。
如果程序里包含了头文件streams.h,则一般库文件还要连接strmbasd.lib、uuid.lib、winmm.lib。
如果你不知道怎样附加库文件的话,可以试下下述的步骤:
(1) 首先你得新建或打开一个解决方案。
(2) 单击VS2005菜单栏中的Project-->XXX Properties-->弹出属性设置对话框,展开Configuration Properties-->展开Linker-->单击Input-->在右边的Addtional Dependencies中添加库。在每个库文件中以空格间隔。
例如:strbase.lib strmiids.lib
[5] 全部搞定了之后,你就可以放心的写程序,调试程序了。加油哦!