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.

124 lines
3.7 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: dsnbuff
  5. //
  6. // Description: Header file for CDSNBuffer. Class used to abstract writting
  7. // DSN buffers to P2 file.
  8. //
  9. // Author: Mike Swafford (MikeSwa)
  10. //
  11. // History:
  12. // 7/3/98 - MikeSwa Created
  13. //
  14. // Copyright (C) 1998 Microsoft Corporation
  15. //
  16. //-----------------------------------------------------------------------------
  17. #ifndef __DSNBUFF_H__
  18. #define __DSNBUFF_H__
  19. #include <windows.h>
  20. #include <dbgtrace.h>
  21. #include "filehc.h"
  22. #include "dsnconv.h"
  23. #define DSN_BUFFER_SIG 'BNSD'
  24. #define DSN_BUFFER_SIZE 1000
  25. class CDSNBuffer
  26. {
  27. public:
  28. DWORD m_dwSignature;
  29. OVERLAPPED m_overlapped;
  30. DWORD m_cbOffset;
  31. DWORD m_cbFileSize;
  32. DWORD m_cFileWrites;
  33. PFIO_CONTEXT m_pDestFile;
  34. BYTE m_pbFileBuffer[DSN_BUFFER_SIZE];
  35. CDSNBuffer();
  36. ~CDSNBuffer();
  37. HRESULT HrInitialize(PFIO_CONTEXT hDestFile);
  38. HRESULT HrWriteBuffer(BYTE *pbInputBuffer, DWORD cbInputBuffer);
  39. HRESULT HrWriteModifiedUnicodeString(LPWSTR pwszString);
  40. HRESULT HrFlushBuffer(OUT DWORD *pcbFileSize);
  41. HRESULT HrSeekForward(IN DWORD cbBytesToSeek, OUT DWORD *pcbFileSize);
  42. //Used to set (and reset) custom conversion contexts. This feature was
  43. //designed explitily for UTF7 encoding of DSN content, but could also
  44. //be used to enforce:
  45. // - RFC822 header formats
  46. // - RFC822 content restricts
  47. void SetConversionContext(CResourceConversionContext *presconv)
  48. {
  49. _ASSERT(presconv);
  50. m_presconv = presconv;
  51. }
  52. //Used to reset to the defaut memcopy
  53. void ResetConversionContext() {m_presconv = &m_defconv;};
  54. HRESULT HrWriteResource(WORD wResourceId, LANGID LangId);
  55. //Encapsulates the functionality of (the nonexistant) LoadStringEx
  56. HRESULT HrLoadResourceString(WORD wResourceId, LANGID LangId,
  57. LPWSTR *pwszResource, DWORD *pcbResource);
  58. protected:
  59. CDefaultResourceConversionContext m_defconv;
  60. CResourceConversionContext *m_presconv;
  61. HRESULT HrPrivWriteBuffer(BOOL fASCII, BYTE *pbInputBuffer,
  62. DWORD cbInputBuffer);
  63. HRESULT HrWriteBufferToFile();
  64. };
  65. //---[ CDSNBuffer::CDSNBuffer ]------------------------------------------------
  66. //
  67. //
  68. // Description:
  69. // Inlined default constructor for CDSNBuffer
  70. // Parameters:
  71. // -
  72. // Returns:
  73. // -
  74. // History:
  75. // 7/3/98 - MikeSwa Created
  76. //
  77. //-----------------------------------------------------------------------------
  78. inline CDSNBuffer::CDSNBuffer()
  79. {
  80. m_dwSignature = DSN_BUFFER_SIG;
  81. m_overlapped.Offset = 0;
  82. m_overlapped.OffsetHigh = 0;
  83. m_overlapped.hEvent = NULL;
  84. m_cbOffset = 0;
  85. m_cbFileSize = 0;
  86. m_cFileWrites = 0;
  87. m_pDestFile = NULL;
  88. m_presconv = &m_defconv;
  89. }
  90. //---[ CDSNBuffer::HrFlushBuffer ]---------------------------------------------
  91. //
  92. //
  93. // Description:
  94. // Flushes remaining buffers to File and returns the total number of bytes
  95. // written to the file.
  96. // Parameters:
  97. // OUT pcbFileSize The size (in bytes) of the file written
  98. // Returns:
  99. // S_OK on success
  100. // History:
  101. // 7/3/98 - MikeSwa Created
  102. //
  103. //-----------------------------------------------------------------------------
  104. inline HRESULT CDSNBuffer::HrFlushBuffer(OUT DWORD *pcbFileSize)
  105. {
  106. HRESULT hr = HrWriteBufferToFile();
  107. _ASSERT(pcbFileSize);
  108. *pcbFileSize = m_cbFileSize;
  109. return hr;
  110. }
  111. #endif //__DSNBUFF_H__