1 #include "streams.h" 2 #include "initguid.h" 3 strmbasd.lib 4 winmm.lib 5 uuid.lib 6 Quartz.lib 输出 AMGetErrorText 函数,如果不调用此函数,此库不是必需的。 7 8 FilterSample.def 文件的内容: 9 LIBRARY FilterSample.ax 10 EXPORTS 11 ; 需要定义的导出函数 12 DllMain PRIVATE 13 DllRegisterServer PRIVATE 14 DllUnregisterServer PRIVATE 15 ; 在基类中已经定义的导出函数 16 DllGetClassObject PRIVATE 17 DllCanUnloadNow PRIVATE 18 19 dllmain.cpp 的代码如下: 20 // dllmain.cpp : 定义 DLL 应用程序的入口点。 21 #include "stdafx.h" 22 #include "streams.h" 23 24 // BOOL APIENTRY DllMain( HMODULE hModule, 25 // DWORD ul_reason_for_call, 26 // LPVOID lpReserved 27 // ) 28 // { 29 // switch (ul_reason_for_call) 30 // { 31 // case DLL_PROCESS_ATTACH: 32 // case DLL_THREAD_ATTACH: 33 // case DLL_THREAD_DETACH: 34 // case DLL_PROCESS_DETACH: 35 // break; 36 // } 37 // return TRUE; 38 // } 39 40 STDAPI DllRegisterServer() 41 { 42 return AMovieDllRegisterServer2(TRUE); 43 } 44 STDAPI DllUnregisterServer() 45 { 46 return AMovieDllRegisterServer2(FALSE); 47 } 48 49 extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID); 50 BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) 51 { 52 return DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved); 53 }
1 #ifndef _FILTER_SAMPLE_H_ 2 #define _FILTER_SAMPLE_H_ 3 4 // {33B57142-BD07-4a77-AE91-A8F6C24A8F40} 5 DEFINE_GUID(CLSID_FilterSample, 6 0x33b57142, 0xbd07, 0x4a77, 0xae, 0x91, 0xa8, 0xf6, 0xc2, 0x4a, 0x8f, 0x40); 7 8 class CFilterSample: public CCritSec, public CBaseFilter 9 { 10 public: 11 CFilterSample(TCHAR *pName,LPUNKNOWN pUnk,HRESULT *hr); 12 virtual ~CFilterSample(); 13 static CUnknown * WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *phr); 14 CBasePin *GetPin(int n); 15 int GetPinCount(); 16 }; 17 18 #endif
FilterSample.cpp 的内容如下:
1 // FilterSample.cpp : 定义 DLL 应用程序的导出函数。 2 // 3 4 #include "stdafx.h" 5 #include "streams.h" 6 #include "initguid.h" 7 8 #include "FilterSample.h" 9 10 // Using this pointer in constructor 11 #pragma warning(disable:4355 4127) 12 13 ////////////////////////////////////////////////////////////////////////// 14 // AMOVIESETUP_FILTER 描述一个 Filter 15 // AMOVIESETUP_PIN 描述 pin 16 // AMOVIESETUP_MEDIATYPE 描述数据类型 17 const AMOVIESETUP_MEDIATYPE sudPinTypes = 18 { 19 &MEDIATYPE_NULL, // Major CLSID 20 &MEDIASUBTYPE_NULL // Minor type 21 }; 22 23 const AMOVIESETUP_PIN psudPins[] = 24 { 25 { 26 L"Input", // Pin's string name 27 FALSE, // Is it rendered 28 FALSE, // Is it an output 29 FALSE, // Allowed none 30 FALSE, // Allowed many 31 &CLSID_NULL, // Connects to filter 32 L"Output", // Connects to pin 33 1, // Number of types 34 &sudPinTypes // Pin information 35 }, 36 { 37 L"Output", // Pin's string name 38 FALSE, // Is it rendered 39 TRUE, // Is it an output 40 FALSE, // Allowed none 41 FALSE, // Allowed many 42 &CLSID_NULL, // Connects to filter 43 L"Input", // Connects to pin 44 1, // Number of types 45 &sudPinTypes // Pin information 46 } 47 }; 48 49 const AMOVIESETUP_FILTER sudInfTee = 50 { 51 &CLSID_FilterSample, // CLSID of filter 52 L"Filter Sample Test Lib", // Filter's name 53 MERIT_DO_NOT_USE, // Filter merit 54 2, // Number of pins 55 psudPins // Pin information 56 }; 57 ////////////////////////////////////////////////////////////////////////// 58 59 CFactoryTemplate g_Templates[1] = 60 { 61 { 62 L"Filter Sample", // Name 63 &CLSID_FilterSample, // CLSID 64 CFilterSample::CreateInstance, // Method to create an instance of MyComponent 65 NULL, // Initialization function 66 &sudInfTee // Set-up information (for filters) 67 } 68 }; 69 int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]); 70 71 72 CFilterSample::CFilterSample(TCHAR *pName,LPUNKNOWN pUnk,HRESULT *hr) 73 :CBaseFilter(NAME("Filter Sample"), pUnk, this, CLSID_FilterSample) 74 { 75 } 76 77 CFilterSample::~CFilterSample() 78 { 79 } 80 81 CBasePin * CFilterSample::GetPin(int n) 82 { 83 return NULL; 84 } 85 int CFilterSample::GetPinCount() 86 { 87 return 0; 88 } 89 90 CUnknown * WINAPI CFilterSample::CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr) 91 { 92 CFilterSample *pFilter = new CFilterSample(NAME("Filter Sample"), pUnk, pHr); 93 if (pFilter== NULL) 94 { 95 *pHr = E_OUTOFMEMORY; 96 } 97 return pFilter; 98 }