PidMpeg1.cpp
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:5k
源码类别:
VC书籍
开发平台:
Visual C++
- // PidMpeg1.cpp : Defines the entry point for the DLL application.
- //
- #include <streams.h> // quartz, includes windows
- #include <stdio.h>
- // Eliminate two expected level 4 warnings from the Microsoft compiler.
- // The class does not have an assignment or copy operator, and so cannot
- // be passed by value. This is normal. This file compiles clean at the
- // highest (most picky) warning level (-W4).
- #pragma warning(disable: 4511 4512)
- #include "CMPEG1Builder.h"
- #include <initguid.h>
- #include "FltGuids.h"
- //
- // setup data
- // List of class IDs and creator functions for the class factory. This
- // provides the link between the OLE entry point in the DLL and an object
- // being created. The class factory will call the static CreateInstance
- CFactoryTemplate g_Templates[] =
- {
- {
- L"PID MPEG1 Builder",
- &CLSID_PID_MPEG1Builder,
- CMPEG1Builder::CreateInstance,
- NULL,
- NULL
- }
- };
- int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
- ////////////////////////////////////////////////////////////////////////
- //
- // Exported entry points for registration and unregistration
- // (in this case they only call through to default implementations).
- //
- ////////////////////////////////////////////////////////////////////////
- HRESULT RegisterPIDInterface(CLSID ClsidInterface,
- LPTSTR strName,
- CLSID ClsidDistributor)
- {
- TCHAR achKey[MAX_PATH];
- TCHAR achClsidInterface[CHARS_IN_GUID];
- TCHAR achClsidDistributor[CHARS_IN_GUID];
- OLECHAR achTemp[CHARS_IN_GUID];
- HKEY hkey, hsubkey;
- LONG lReturn;
- HRESULT hr;
- hr = StringFromGUID2(ClsidInterface, achTemp, CHARS_IN_GUID);
- if (SUCCEEDED(hr))
- {
- wsprintf(achClsidInterface, "%ls", achTemp);
- hr = StringFromGUID2(ClsidDistributor, achTemp, CHARS_IN_GUID);
- }
- if (FAILED(hr)) return hr;
- wsprintf(achClsidDistributor, "%ls", achTemp);
- wsprintf(achKey, "Interface\%s", achClsidInterface);
- lReturn = RegCreateKey(HKEY_CLASSES_ROOT, achKey, &hkey);
- if (ERROR_SUCCESS == lReturn)
- {
- if (NULL != strName)
- {
- // Set the interface name
- RegSetValue(hkey, NULL, REG_SZ, strName, lstrlen(strName)+1);
- }
- lReturn = RegCreateKey(hkey, "Distributor", &hsubkey);
- if (ERROR_SUCCESS == lReturn)
- {
- // Set the default value of "Distributor" key
- RegSetValue(hsubkey, NULL, REG_SZ, achClsidDistributor,
- lstrlen(achClsidDistributor)+1);
- RegCloseKey(hsubkey);
- }
- RegCloseKey(hkey);
- }
- return HRESULT_FROM_WIN32(lReturn);
- }
- HRESULT UnregisterPIDInterface(REFCLSID ClsidInterface)
- {
- HKEY hkey;
- LONG lReturn;
- HRESULT hr;
- TCHAR achClsidInterface[CHARS_IN_GUID];
- OLECHAR achTemp[CHARS_IN_GUID];
- // comvert CLSID to OLE string
- hr = StringFromGUID2(ClsidInterface, achTemp, CHARS_IN_GUID);
- if (FAILED(hr)) return hr;
- // convert OLE string to ANSI (as that's
- // all that WIN95 Reg* calls can handle
- wsprintf(achClsidInterface, "%ls", achTemp);
- // open Interface key
- lReturn = RegOpenKeyEx(HKEY_CLASSES_ROOT, TEXT("Interface"),
- 0, MAXIMUM_ALLOWED, &hkey);
- if (ERROR_SUCCESS == lReturn)
- {
- // if successful, eliminate subkey and close
- // Interface key
- EliminateSubKey(hkey, achClsidInterface);
- RegCloseKey(hkey);
- }
- return HRESULT_FROM_WIN32(lReturn);
- }
- //
- // DllRegisterServer
- //
- // Exported entry points for registration and unregistration
- //
- STDAPI DllRegisterServer()
- {
- HRESULT hr = NOERROR;
- // Register as DirectShow Plug-in Distributor
- // HKEY_CLASSES_ROOTInterfaceIIDDistributor
- hr = RegisterPIDInterface(IID_IMPEG1Builder, TEXT("IMPEG1Builder"),
- CLSID_PID_MPEG1Builder);
- if (SUCCEEDED(hr))
- {
- hr = AMovieDllRegisterServer2(TRUE);
- }
- return hr;
- }
- //
- // DllUnregisterServer
- //
- STDAPI DllUnregisterServer()
- {
- HRESULT hr = NOERROR;
- // Remove DirectShow Plug-in Distributor entries
- hr = UnregisterPIDInterface(IID_IMPEG1Builder);
- if (SUCCEEDED(hr))
- {
- hr = AMovieDllRegisterServer2(FALSE);
- }
- return hr;
- }
- //
- // DllEntryPoint
- //
- extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
- BOOL APIENTRY DllMain(HANDLE hModule,
- DWORD dwReason,
- LPVOID lpReserved)
- {
- return DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved);
- }
- CUnknown * WINAPI CMPEG1Builder::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr)
- {
- ASSERT(phr);
- // Verify: we only allow filter graph manager to create us!
- if (!lpunk)
- {
- *phr = VFW_E_NEED_OWNER;
- return NULL;
- }
- IGraphBuilder * pGraphBuilder = NULL;
- if (FAILED(lpunk->QueryInterface(IID_IGraphBuilder, (void**)&pGraphBuilder)))
- {
- *phr = E_FAIL;
- return NULL;
- }
- if (pGraphBuilder)
- {
- pGraphBuilder->Release();
- }
- // Safe to create our COM object
- CUnknown *punk = new CMPEG1Builder(lpunk, phr);
- if (punk == NULL)
- {
- if (phr)
- {
- *phr = E_OUTOFMEMORY;
- }
- }
- return punk;
- }