dllsetup.cpp.svn-base

来自「ffshow源码」· SVN-BASE 代码 · 共 693 行 · 第 1/2 页

SVN-BASE
693
字号
//------------------------------------------------------------------------------// File: DllSetup.cpp//// Desc: DirectShow base classes.//// Copyright (c) 1992-2002 Microsoft Corporation.  All rights reserved.//------------------------------------------------------------------------------#include "stdafx.h"//---------------------------------------------------------------------------// definesstatic const int MAX_KEY_LEN=260;//---------------------------------------------------------------------------// externally defined functions/variableextern int g_cTemplates;extern CFactoryTemplate g_Templates[];//---------------------------------------------------------------------------//// EliminateSubKey//// Try to enumerate all keys under this one.// if we find anything, delete it completely.// Otherwise just delete it.//// note - this was pinched/duplicated from// Filgraph\Mapper.cpp - so should it be in// a lib somewhere?////---------------------------------------------------------------------------STDAPIEliminateSubKey( HKEY hkey, LPTSTR strSubKey ){  HKEY hk;  if (0 == lstrlen(strSubKey) ) {      // defensive approach      return E_FAIL;  }  LONG lreturn = RegOpenKeyEx( hkey                             , strSubKey                             , 0                             , MAXIMUM_ALLOWED                             , &hk );  ASSERT(    lreturn == ERROR_SUCCESS          || lreturn == ERROR_FILE_NOT_FOUND          || lreturn == ERROR_INVALID_HANDLE );  if( ERROR_SUCCESS == lreturn )  {    // Keep on enumerating the first (zero-th)    // key and deleting that    for( ; ; )    {      TCHAR Buffer[MAX_KEY_LEN];      DWORD dw = MAX_KEY_LEN;      FILETIME ft;      lreturn = RegEnumKeyEx( hk                            , 0                            , Buffer                            , &dw                            , NULL                            , NULL                            , NULL                            , &ft);      ASSERT(    lreturn == ERROR_SUCCESS              || lreturn == ERROR_NO_MORE_ITEMS );      if( ERROR_SUCCESS == lreturn )      {        EliminateSubKey(hk, Buffer);      }      else      {        break;      }    }    RegCloseKey(hk);    RegDeleteKey(hkey, strSubKey);  }  return NOERROR;}//---------------------------------------------------------------------------//// AMovieSetupRegisterServer()//// registers specfied file "szFileName" as server for// CLSID "clsServer".  A description is also required.// The ThreadingModel and ServerType are optional, as// they default to InprocServer32 (i.e. dll) and Both.////---------------------------------------------------------------------------STDAPIAMovieSetupRegisterServer( CLSID   clsServer                         , LPCWSTR szDescription                         , LPCWSTR szFileName                         , LPCWSTR szThreadingModel = L"Both"                         , LPCWSTR szServerType     = L"InprocServer32" ){  // temp buffer  //  TCHAR achTemp[MAX_PATH];  // convert CLSID uuid to string and write  // out subkey as string - CLSID\{}  //  OLECHAR szCLSID[CHARS_IN_GUID];  HRESULT hr = StringFromGUID2( clsServer                              , szCLSID                              , CHARS_IN_GUID );  ASSERT( SUCCEEDED(hr) );  // create key  //  HKEY hkey;  wsprintf( achTemp, TEXT("CLSID\\%ls"), szCLSID );  LONG lreturn = RegCreateKey( HKEY_CLASSES_ROOT                             , (LPCTSTR)achTemp                             , &hkey              );  if( ERROR_SUCCESS != lreturn )  {    return AmHresultFromWin32(lreturn);  }  // set description string  //  wsprintf( achTemp, TEXT("%ls"), szDescription );  lreturn = RegSetValue( hkey                       , (LPCTSTR)NULL                       , REG_SZ                       , achTemp                       , sizeof(achTemp) );  if( ERROR_SUCCESS != lreturn )  {    RegCloseKey( hkey );    return AmHresultFromWin32(lreturn);  }  // create CLSID\\{"CLSID"}\\"ServerType" key,  // using key to CLSID\\{"CLSID"} passed back by  // last call to RegCreateKey().  //  HKEY hsubkey;  wsprintf( achTemp, TEXT("%ls"), szServerType );  lreturn = RegCreateKey( hkey                        , achTemp                        , &hsubkey     );  if( ERROR_SUCCESS != lreturn )  {    RegCloseKey( hkey );    return AmHresultFromWin32(lreturn);  }  // set Server string  //  wsprintf( achTemp, TEXT("%ls"), szFileName );  lreturn = RegSetValue( hsubkey                       , (LPCTSTR)NULL                       , REG_SZ                       , (LPCTSTR)achTemp                       , sizeof(TCHAR) * (lstrlen(achTemp)+1) );  if( ERROR_SUCCESS != lreturn )  {    RegCloseKey( hkey );    RegCloseKey( hsubkey );    return AmHresultFromWin32(lreturn);  }  wsprintf( achTemp, TEXT("%ls"), szThreadingModel );  lreturn = RegSetValueEx( hsubkey                         , TEXT("ThreadingModel")                         , 0L                         , REG_SZ                         , (CONST BYTE *)achTemp                         , sizeof(TCHAR) * (lstrlen(achTemp)+1) );  // close hkeys  //  RegCloseKey( hkey );  RegCloseKey( hsubkey );  // and return  //  return HRESULT_FROM_WIN32(lreturn);}//---------------------------------------------------------------------------//// AMovieSetupUnregisterServer()//// default ActiveMovie dll setup function// - to use must be called from an exported//   function named DllRegisterServer()////---------------------------------------------------------------------------STDAPIAMovieSetupUnregisterServer( CLSID clsServer ){  // convert CLSID uuid to string and write  // out subkey CLSID\{}  //  OLECHAR szCLSID[CHARS_IN_GUID];  HRESULT hr = StringFromGUID2( clsServer                              , szCLSID                              , CHARS_IN_GUID );  ASSERT( SUCCEEDED(hr) );  TCHAR achBuffer[MAX_KEY_LEN];  wsprintf( achBuffer, TEXT("CLSID\\%ls"), szCLSID );  // delete subkey  //  hr = EliminateSubKey( HKEY_CLASSES_ROOT, achBuffer );  ASSERT( SUCCEEDED(hr) );  // return  //  return NOERROR;}//---------------------------------------------------------------------------//// AMovieSetupRegisterFilter through IFilterMapper2////---------------------------------------------------------------------------STDAPIAMovieSetupRegisterFilter2( const AMOVIESETUP_FILTER * const psetupdata                          , IFilterMapper2 *                 pIFM2                          , BOOL                             bRegister  ){  DbgLog((LOG_TRACE, 3, TEXT("= AMovieSetupRegisterFilter")));  // check we've got data  //  if( NULL == psetupdata ) return S_FALSE;  // unregister filter  // (as pins are subkeys of filter's CLSID key  // they do not need to be removed separately).  //  DbgLog((LOG_TRACE, 3, TEXT("= = unregister filter")));  HRESULT hr = pIFM2->UnregisterFilter(      0,                        // default category      0,                        // default instance name      *psetupdata->clsID );  if( bRegister )  {    REGFILTER2 rf2;    rf2.dwVersion = 1;    rf2.dwMerit = psetupdata->dwMerit;    rf2.cPins = psetupdata->nPins;    rf2.rgPins = psetupdata->lpPin;        // register filter    //    DbgLog((LOG_TRACE, 3, TEXT("= = register filter")));    hr = pIFM2->RegisterFilter(*psetupdata->clsID                             , psetupdata->strName                             , 0 // moniker                             , 0 // category                             , NULL // instance                             , &rf2);  }  // handle one acceptable "error" - that  // of filter not being registered!  // (couldn't find a suitable #define'd  // name for the error!)  //  if( 0x80070002 == hr)    return NOERROR;  else    return hr;}//---------------------------------------------------------------------------//// RegisterAllServers()////---------------------------------------------------------------------------STDAPIRegisterAllServers( LPCWSTR szFileName, BOOL bRegister ){  HRESULT hr = NOERROR;  for( int i = 0; i < g_cTemplates; i++ )  {    // get i'th template    //    const CFactoryTemplate *pT = &g_Templates[i];    DbgLog((LOG_TRACE, 2, TEXT("- - register %ls"),           (LPCWSTR)pT->m_Name ));    // register CLSID and InprocServer32    //    if( bRegister )    {      hr = AMovieSetupRegisterServer( *(pT->m_ClsID)                                    , (LPCWSTR)pT->m_Name                                    , szFileName );    }    else    {      hr = AMovieSetupUnregisterServer( *(pT->m_ClsID) );    }    // check final error for this pass    // and break loop if we failed    //    if( FAILED(hr) )      break;  }  return hr;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?