|
一、配置方法
1、先编译Samples\C++\DirectShow\BaseClasses中的工程文件。注意工程的默认选项是D
ebug_Unicode的,在非Unicode的工程中使用还需要编译Debug版本的。
“DXSDK90\SAMPLES\C++\DIRECTSHOW\BASECLASSES\baseclasses.dsw的release版本”,指的是运行DXSDK90\SAMPLES\C++\DIRECTSHOW\BASECLASSES\baseclasses.dsw前,先在VC中选择Build->Set Active Configuration,再在对话框中选择BaseClasses-Win32 Release??
2、需要设置好VC中目录的设置
include的目录中添加 C:\DXSDK\Samples\C++\DirectShow\BaseClasses
Lib的目录中添加 C:\DXSDK\Samples\C++\DirectShow\BaseClasses\Debug
3、使用DirectShow时应该先执行
CoInitialize (NULL);
初始化COM,结束前
CoUninitialize();
关闭COM
4、使用DirectShow的工程需要添加下面两个头文件
#include <streams.h> //DS接口、基类的定义
#include <atlbase.h> //CComPtr模板的定义
同时需要调整编译的选项
#pragma comment(lib,"strmbasd.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(linker,"/NODEFAULTLIB:libcmtd.lib")
注意,VC自带的库中也有strmbasd.lib文件。一定要保证连接到DS的库中,否则会出现
strmbasd.lib(dllsetup.obj) : error LNK2001: unresolved external symbol "class CFactoryTemplate * g_Templates" (?g_Templates@@3PAVCFactoryTemplate@@A)
strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol "class CFactoryTemplate * g_Templates" (?g_Templates@@3PAVCFactoryTemplate@@A)
strmbasd.lib(dllsetup.obj) : error LNK2001: unresolved external symbol "int g_cTemplates" (?g_cTemplates@@3HA)
strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol "int g_cTemplates" (?g_cTemplates@@3HA)
之类的错误。
出现上面这个错误还可以通过设置
『『First, Open dshow.sln, right click BaseClasses, select Properties,
in BaseClasses Property Pages
Configuration Properties
Librarian
Command Line
Additional Options: ( I add the following)
../../../../lib/strmiids.lib /nodefaultlib
rebuild
then it is done
』』
二.编译后出现的错误:
1、syntax error : identifier 'DWORD_PTR'
如果你安装了Miscrosof Platform SDK, 你也许会看到:
Compiling...
e:\directx9\samples\c++\directshow\baseclasses\wxutil.h(53) : error C2061: syntax error : identifier 'DWORD_PTR'
e:\directx9\samples\c++\directshow\baseclasses\ctlutil.h(43) : error C2504: 'IBasicVideo2' : base class undefined
e:\directx9\samples\c++\directshow\baseclasses\ctlutil.h(904) : error C2146: syntax error : missing ';' before identifier 'm_dwAdvise'
e:\directx9\samples\c++\directshow\baseclasses\ctlutil.h(90) : error C2501: 'DWORD_PTR' : missing storage-class or type specifierse
如果发生这种情况,你应该从"Tools"目录中选择"Option",然后在include directory中将Platform SDK加到
VC inlcude之前:
2、LINK : fatal error LNK1104: cannot open file "mfc42ud.lib"
mfc42ud.lib是专门给unicode用的
build-->set active Configuration--> XXX win32 debug 这样就可以了
3、“CComPtr< ”怎么用?
CComPtr<ISmbppLongConnectApiEx> m_spApi;在控制台程序中可以编译成功,但mfc中报错,怎么回事?在线等待一下是错误信息:
error C2143: syntax error : missing ';' before '<'
error C2501: 'CComPtr' : missing storage-class or type specifiers
error C2059: syntax error : '<'
error C2238: unexpected token(s) preceding ';'
原因:缺少文件,在vc6中是atlbase.h,可能在.net中是atlcomcli.h
解决方法:在stdafx.h中加入#include <atlbase.h>
4、'ISampleGrabber' : undeclared identifier
加入代码#include "C:\DXSDK\Samples\C++\DirectShow\Common\dshowutil.cpp 并且需要在project ->settings -> link 中object/libary modules 中填加C:\DXSDK\Samples\C++\DirectShow\BaseClasses\debug\strmbasd.lib winmm.lib ,同时要保证stdafx.h中 有#include <atlbase.h> #include <streams.h> #include <qedit.h>
5、调用CoInitializeEx(),编译后显示未定义
CoInitializeEx()是利用COM组件时每个线程都要调用的函数,使用这个函数需要有如下设置:在Project -> setting -> C/C++标签下的Preprocessor definitions中加入"_WIN32_WINNT=0x400"语句
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=999234
|
|