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.

212 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module psub.cpp | Implementation of Writer
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 08/18/1999
  9. TBD:
  10. Add comments.
  11. Revision History:
  12. Name Date Comments
  13. aoltean 08/18/1999 Created
  14. aoltean 09/22/1999 Making console output clearer
  15. mikejohn 09/19/2000 176860: Added calling convention methods where missing
  16. --*/
  17. /////////////////////////////////////////////////////////////////////////////
  18. // Defines
  19. // C4290: C++ Exception Specification ignored
  20. #pragma warning(disable:4290)
  21. // warning C4511: 'CVssCOMApplication' : copy constructor could not be generated
  22. #pragma warning(disable:4511)
  23. // warning C4127: conditional expression is constant
  24. #pragma warning(disable:4127)
  25. /////////////////////////////////////////////////////////////////////////////
  26. // Includes
  27. #include <wtypes.h>
  28. #include <stddef.h>
  29. #include <oleauto.h>
  30. #include <comadmin.h>
  31. #include "vs_assert.hxx"
  32. // ATL
  33. #include <atlconv.h>
  34. #include <atlbase.h>
  35. extern CComModule _Module;
  36. #include <atlcom.h>
  37. #include "vs_inc.hxx"
  38. #include "vss.h"
  39. #include "comadmin.hxx"
  40. #include "vsevent.h"
  41. #include "vswriter.h"
  42. #include "resource.h"
  43. #include "psub.h"
  44. /////////////////////////////////////////////////////////////////////////////
  45. // constants
  46. const WCHAR g_wszPSubApplicationName[] = L"PSub";
  47. const MAX_BUFFER = 1024;
  48. // {621D30C6-EC47-4b66-A91A-D3FA03472FCA}
  49. GUID CLSID_PSub =
  50. { 0x621d30c6, 0xec47, 0x4b66, { 0xa9, 0x1a, 0xd3, 0xfa, 0x3, 0x47, 0x2f, 0xca } };
  51. CVssPSubWriter::CVssPSubWriter()
  52. {
  53. Initialize
  54. (
  55. CLSID_PSub,
  56. L"PSUB",
  57. VSS_UT_USERDATA,
  58. VSS_ST_OTHER
  59. );
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // class CVssPSubWriter
  63. bool STDMETHODCALLTYPE CVssPSubWriter::OnPrepareSnapshot()
  64. {
  65. WCHAR wszBuffer[MAX_BUFFER];
  66. WCHAR wszBuffer2[MAX_BUFFER];
  67. swprintf( wszBuffer, L"OnPrepare\n\t#volumes = %ld\n", GetCurrentVolumeCount() );
  68. for(int nIndex = 0; nIndex < GetCurrentVolumeCount(); nIndex++) {
  69. swprintf( wszBuffer2, L"\tVolume no. %ld: %s\n", nIndex, GetCurrentVolumeArray()[nIndex]);
  70. wcscat( wszBuffer, wszBuffer2 );
  71. }
  72. WCHAR wszPwd[MAX_PATH];
  73. DWORD dwChars = GetCurrentDirectoryW( MAX_PATH, wszPwd);
  74. bool bPwdIsAffected = IsPathAffected( wszPwd );
  75. if (dwChars > 0) {
  76. swprintf( wszBuffer2, L"Current directory %s is affected by snapshot? %s\n\n",
  77. wszPwd, bPwdIsAffected? L"Yes": L"No");
  78. wcscat( wszBuffer, wszBuffer2 );
  79. }
  80. MessageBoxW( NULL, wszBuffer, L"Writer test", MB_OK | MB_SERVICE_NOTIFICATION );
  81. return true;
  82. }
  83. bool STDMETHODCALLTYPE CVssPSubWriter::OnFreeze()
  84. {
  85. WCHAR wszBuffer[MAX_BUFFER];
  86. swprintf( wszBuffer, L"OnFreeze\n\tmy level = %d\n\n", GetCurrentLevel() );
  87. MessageBoxW( NULL, wszBuffer, L"Writer test", MB_OK | MB_SERVICE_NOTIFICATION );
  88. return true;
  89. }
  90. bool STDMETHODCALLTYPE CVssPSubWriter::OnThaw()
  91. {
  92. MessageBoxW( NULL, L"OnThaw", L"Writer test", MB_OK | MB_SERVICE_NOTIFICATION );
  93. return true;
  94. }
  95. bool STDMETHODCALLTYPE CVssPSubWriter::OnAbort()
  96. {
  97. MessageBoxW( NULL, L"OnAbort", L"Writer test", MB_OK | MB_SERVICE_NOTIFICATION );
  98. return true;
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // DLL methods
  102. CComModule _Module;
  103. BEGIN_OBJECT_MAP(ObjectMap)
  104. OBJECT_ENTRY(CLSID_PSub, CVssPSubWriter)
  105. END_OBJECT_MAP()
  106. /////////////////////////////////////////////////////////////////////////////
  107. // DLL Entry Point
  108. extern "C"
  109. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  110. {
  111. if (dwReason == DLL_PROCESS_ATTACH)
  112. {
  113. // Set the correct tracing context. This is an inproc DLL
  114. g_cDbgTrace.SetContextNum(VSS_CONTEXT_DELAYED_DLL);
  115. // initialize COM module
  116. _Module.Init(ObjectMap, hInstance);
  117. // optimization
  118. DisableThreadLibraryCalls(hInstance);
  119. }
  120. else if (dwReason == DLL_PROCESS_DETACH)
  121. _Module.Term();
  122. return TRUE; // ok
  123. }
  124. /////////////////////////////////////////////////////////////////////////////
  125. // Used to determine whether the DLL can be unloaded by OLE
  126. STDAPI DllCanUnloadNow(void)
  127. {
  128. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  129. }
  130. /////////////////////////////////////////////////////////////////////////////
  131. // Returns a class factory to create an object of the requested type
  132. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  133. {
  134. return _Module.GetClassObject(rclsid, riid, ppv);
  135. }
  136. /////////////////////////////////////////////////////////////////////////////
  137. // DllRegisterServer - Adds entries to the system registry
  138. STDAPI DllRegisterServer(void)
  139. {
  140. return _Module.RegisterServer(TRUE);
  141. }
  142. /////////////////////////////////////////////////////////////////////////////
  143. // DllUnregisterServer - Removes entries from the system registry
  144. STDAPI DllUnregisterServer(void)
  145. {
  146. _Module.UnregisterServer();
  147. return S_OK;
  148. }