DirectShow開發的環境配置和常見問題

來源:互聯網
上載者:User

首先去微軟官方網站下載SDK

如果你下載的是2004版沒有directshow工程,再下載這個補充包

http://www.microsoft.com/download/en/confirmation.aspx?displayLang=en&id=11388

一、配置方法

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") 

或者在附加依賴庫中添加

strmbasd.lib winmm.lib Netapi32.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)

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

error LNK2001: unresolved external symbol _Netbios@4

之類的錯誤。

二.編譯後出現的錯誤:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.