Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.8 KiB

  1. //=================================================================
  2. //
  3. // DllWrapperCreatorReg.h
  4. //
  5. // Copyright (c) 1999-2002 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. /******************************************************************************
  9. * #includes to Register this class with the CResourceManager.
  10. *****************************************************************************/
  11. #include "ResourceManager.h"
  12. #include <ProvExce.h>
  13. //
  14. // resource management failures
  15. //
  16. extern BOOL bAddInstanceCreatorFailure ;
  17. /******************************************************************************
  18. * Register this class with the CResourceManager.
  19. *****************************************************************************/
  20. template<class a_T, const GUID* a_pguidT, const TCHAR* a_ptstrDllName>
  21. class CDllApiWraprCreatrReg
  22. {
  23. public:
  24. CDllApiWraprCreatrReg()
  25. {
  26. try
  27. {
  28. BOOL bNonFailure =
  29. CResourceManager::sm_TheResourceManager.AddInstanceCreator(*a_pguidT, ApiWraprCreatrFn);
  30. if ( FALSE == bNonFailure )
  31. {
  32. bAddInstanceCreatorFailure = TRUE ;
  33. }
  34. }
  35. catch ( CHeap_Exception& e_HE )
  36. {
  37. bAddInstanceCreatorFailure = TRUE ;
  38. }
  39. }
  40. ~CDllApiWraprCreatrReg(){}
  41. static CResource* ApiWraprCreatrFn
  42. (
  43. PVOID pData
  44. )
  45. {
  46. a_T* t_pT = NULL ;
  47. if( !(t_pT = (a_T*) new a_T(a_ptstrDllName) ) )
  48. {
  49. throw CHeap_Exception( CHeap_Exception::E_ALLOCATION_ERROR ) ;
  50. }
  51. try
  52. {
  53. if( t_pT->Init() )
  54. {
  55. return t_pT ;
  56. }
  57. else
  58. {
  59. delete t_pT ;
  60. return NULL ;
  61. }
  62. }
  63. catch( ... )
  64. {
  65. delete t_pT ;
  66. throw ;
  67. }
  68. }
  69. };