directshow环境配置

文本预览:
一、配置方法
1、先编译SamplesC++DirectShowBaseClasses中的工程文件。注意工程的默认选项是D
ebug_Unicode的,在非Unicode的工程中使用还需要编译Debug版本的。
“DXSDK90SAMPLESC++DIRECTSHOWBASECLASSESbaseclasses.dsw的release版本”,指的是运行DXSDK90SAMPLESC++DIRECTSHOWBASECLASSESbaseclasses.dsw前,先在VC中选择Build->Set Active Configuration,再在对话框中选择BaseClasses-Win32 Release??
2、需要设置好VC中目录的设置
include的目录中添加 C:DXSDKSamplesC++DirectShowBaseClasses
Lib的目录中添加 C:DXSDKSamplesC++DirectShowBaseClassesDebug
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:directx9samplesc++directshowbaseclasseswxutil.h(53) : error C2061: syntax error : identifier 'DWORD_PTR'
e:directx9samplesc++directshowbaseclassesctlutil.h(43) : error C2504: 'IBasicVideo2' : base class undefined
e:directx9samplesc++directshowbaseclassesctlutil.h(904) : error C2146: syntax error : missing ';' before identifier 'm_dwAdvise'
e:directx9samplesc++directshowbaseclassesctlutil.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:DXSDKSamplesC++DirectShowCommondshowutil.cpp 并且需要在project ->settings -> link 中object/libary modules 中填加C:DXSDKSamplesC++DirectShowBaseClassesdebugstrmbasd.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"语句

开发环境
SDK:DirectX9.0b (Summer 2003)
Visual C++ 6.0
参考文档:SDK文档
1) DirectShow->Getting Started->Setting Up the Build Environment
2) DirectShow->DirectShow Reference->DirectShow Base Classes->Using the DirectShow Base Classes
3) DirectShow->Getting Started->How To Play a File
测试例子:SDK文档
DirectShow->Getting Started->How To Play a File
配置说明:
1. Tools->Options->Directories
Include - 添加<SDK root>Include
Lib - 添加<SDK root>Lib
- 添加<SDK root>SAMPLESC++DirectShowBASECLASSESDEBUG // [注1]
2. Build BaseClasses
打开<SDK root>SamplesC++DirectShowBaseClassesbaseclasses.dsp,编译debug得到Strmbasd.lib。 // [注2]
3. Project->Setting->Link
添加Strmbasd.lib
4. 添加头文件
#include <Dshow.h> // 所有DirectShow应用程序必备
#include <Streams.h> // 使用DirectShow基类
源代码如下,代码分析见参考文档3)
#include <Dshow.h>
#include <Streams.h>
#include <stdio.h>
void main(void)
{
IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;
// Initialize the COM library.
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
{
printf("ERROR - Could not initialize COM library");
return;
}
// Create the filter graph manager and query for interfaces.
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGraph);
if (FAILED(hr))
{
printf("ERROR - Could not create the Filter Graph Manager.");
return;
}
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
// Build the graph. IMPORTANT: Change this string to a file on your system.
// hr = pGraph->RenderFile(L"C:\Example.avi", NULL);
hr = pGraph->RenderFile(L"E:\DXSDK\Samples\Media\chicken.wmv", NULL); // 打开一个媒体文件
if (SUCCEEDED(hr))
{
// Run the graph.
hr = pControl->Run();
if (SUCCEEDED(hr))
{
// Wait for completion.
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);
// Note: Do not use INFINITE in a real application, because it
// can block indefinitely.
}
}
pControl->Release();
pEvent->Release();
pGraph->Release();
CoUninitialize();
}
注1:该处可根据需要添加不同版本,如RELEASE/Debug_Unicode/Release_Unicode。
注2:debug - strmbasd.lib;release - strmbase.lib;另外还有对应的Unicode版本。
注3:步骤3缺,将导致
error LNK2001: unresolved external symbol _IID_IMediaEvent
error LNK2001: unresolved external symbol _IID_IMediaControl
error LNK2001: unresolved external symbol _CLSID_FilterGraph
error LNK2001: unresolved external symbol _IID_IGraphBuilder
Debug/Howtoplayafile.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值