关于directshow的开发常见问题

关于directshow的开发常见问题



一、配置方法

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)
之类的错误。

二.编译后出现的错误:

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"语句


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值