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.

140 lines
2.7 KiB

  1. #include <pch.cxx>
  2. #pragma hdrstop
  3. #include "trkcom.hxx"
  4. const TCHAR tszKeyNameLinkTrack[] = TEXT("System\\CurrentControlSet\\Services\\TrkWks\\Parameters");
  5. long g_cDllRefs = 0;
  6. #if DBG
  7. DWORD g_Debug = TRKDBG_ERROR;
  8. CTrkConfiguration g_config;
  9. #endif
  10. EXTERN_C int APIENTRY DllMain (HINSTANCE hInstance,
  11. DWORD dwReason,
  12. LPVOID lpReserved)
  13. {
  14. if( DLL_PROCESS_ATTACH == dwReason )
  15. {
  16. #if DBG
  17. g_config.Initialize( );
  18. g_Debug = g_config._dwDebugFlags;
  19. #endif
  20. TrkDebugCreate( TRK_DBG_FLAGS_WRITE_TO_DBG, "TrkCom" );
  21. InterlockedIncrement( &g_cDllRefs );
  22. }
  23. else if( DLL_PROCESS_DETACH == dwReason )
  24. InterlockedDecrement( &g_cDllRefs );
  25. return TRUE;
  26. }
  27. STDAPI DllCanUnloadNow (void)
  28. {
  29. return ResultFromScode( (0 == g_cDllRefs) ? S_OK : S_FALSE );
  30. }
  31. EXTERN_C STDAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID *ppv)
  32. {
  33. *ppv = NULL;
  34. if (!IsEqualCLSID (rclsid, CLSID_TrackFile))
  35. return ResultFromScode (CLASS_E_CLASSNOTAVAILABLE);
  36. CClassFactory *pClassFactory = new CClassFactory ();
  37. if (pClassFactory == NULL)
  38. return ResultFromScode (E_OUTOFMEMORY);
  39. HRESULT hr = pClassFactory->QueryInterface (riid, ppv);
  40. pClassFactory->Release ();
  41. return hr;
  42. }
  43. STDMETHODIMP
  44. CClassFactory::QueryInterface( REFIID riid, void **ppvObject )
  45. {
  46. IUnknown *pUnk = NULL;
  47. if( riid == IID_IUnknown
  48. ||
  49. riid == IID_IClassFactory
  50. )
  51. {
  52. pUnk = this;
  53. }
  54. if( pUnk != NULL )
  55. {
  56. pUnk->AddRef();
  57. *ppvObject = pUnk;
  58. return S_OK;
  59. }
  60. *ppvObject = NULL;
  61. return E_NOINTERFACE;
  62. }
  63. STDMETHODIMP_(ULONG)
  64. CClassFactory::AddRef( void )
  65. {
  66. long cNew;
  67. cNew = InterlockedIncrement( &_cRefs );
  68. return( cNew );
  69. }
  70. STDMETHODIMP_(ULONG)
  71. CClassFactory::Release( void )
  72. {
  73. long cNew;
  74. cNew = InterlockedDecrement( &_cRefs );
  75. if( 0 == cNew )
  76. delete this;
  77. return( cNew >= 0 ? cNew : 0 );
  78. }
  79. STDMETHODIMP
  80. CClassFactory::CreateInstance( IUnknown *pUnkOuter,
  81. REFIID riid,
  82. void **ppvObject )
  83. {
  84. CTrackFile *pObj = NULL;
  85. if( pUnkOuter != NULL )
  86. {
  87. return( CLASS_E_NOAGGREGATION );
  88. }
  89. pObj = (CTrackFile*) new CTrackFile( );
  90. if( pObj == NULL )
  91. {
  92. return( E_OUTOFMEMORY );
  93. }
  94. return pObj->QueryInterface( riid, ppvObject );
  95. }
  96. STDMETHODIMP
  97. CClassFactory::LockServer( BOOL fLock )
  98. {
  99. if( fLock )
  100. AddRef();
  101. else
  102. Release();
  103. return S_OK;
  104. }