(轉載)DirectShow VC6.0 開發環境的搭建

今天要用DirectShow做一個音頻採集程序,結果遇到的第一個問題便是開發環境的搭建,需要幾步準備。

1)下載支持DirectShow的SDK

2)將SDK中的include和lib目錄配置到VC6.0下(一般SDK在安裝過程中會自己配置)

3)編譯SDK中samples中提供的項目,得到Strmbasd.lib winmm.lib庫文件,這個要在新建的DirectShow工程中引用

 

第一步,我爲了能夠開發DirectShow程序,曾想過用VC6.0或者VS2005,只要這兩個有一個配置成功了,我便用哪個,因爲我對開發環境並不關注。

我先後下載並安裝了微軟提供的兩個SDK,一個是Windows.Server.2003.Platform.SDK.Feb.2003.Edition-QUANTUM,另一個是DXSDK_Aug08。這兩個到後來我沒有配置成功,所以這裏略過,我沒配置成功不代表別人就配置不成。

我最後下載了成功配置的SDK,這就是dx9sdk,在百度裏搜索“DirectX9.0b SDK Summer 2003”應該可以搜到並下載。安裝之後,果然有這個目錄:<SDK root>/SAMPLES/C++/DirectShow/BASECLASSES

下面,進入第二步。

第二步,打開VC6.0

Tools->Options->Directories
Include - 添加<SDK root>/Include
Lib       - 添加<SDK root>/Lib
            - 添加<SDK root>/SAMPLES/C++/DirectShow/BASECLASSES/DEBUG  //這個目錄在第3步之後會出現的

第三步,對於<SDK root>/SAMPLES/C++/DirectShow/BASECLASSES的編譯,我要轉引網上一篇我十分感激的文章:

轉引開始:

 

我也是個初學者,要是以下的文章有什麼錯誤,請給我留言,謝謝!

[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了,呵呵!你調出來了嗎?

 

轉引結束 原文地址如下:http://blog.chinaunix.net/u1/33950/showart_716130.html

上面的轉引,講述瞭如何編譯出我們需要的庫文件Strmbasd.lib,按照轉引上的方法生成了這個庫文件後,在VC6.0的Project->Setting->Link
添加Strmbasd.lib winmm.lib

 

 

以上準備結束之後,就可以編譯我們的DirectShow程序啦~~~

一個參考源代碼,可以用來測試

#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://DX90SDK//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();
}

 

完。

 


本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/out_of_memory/archive/2008/12/10/3486726.aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章