当前位置:   article > 正文

Using Streams_stream using

stream using

The example in this topic demonstrates how to use basic NTFS file system streams.

This example creates a file, called "TestFile," with a size of 16 bytes. However, the file also has an additional ::$DATA stream type, named "Stream" which adds an additional 23 bytes that is not reported by the operating system. Therefore, when you view the file size property for the file, you see only the size of default ::$DATA stream for the file.

C++Copy

  1. #include <windows.h>
  2. #include <stdio.h>
  3. void main( )
  4. {
  5. HANDLE hFile, hStream;
  6. DWORD dwRet;
  7. hFile = CreateFile( TEXT("TestFile"), // Filename
  8. GENERIC_WRITE, // Desired access
  9. FILE_SHARE_WRITE, // Share flags
  10. NULL, // Security Attributes
  11. OPEN_ALWAYS, // Creation Disposition
  12. 0, // Flags and Attributes
  13. NULL ); // OVERLAPPED pointer
  14. if( hFile == INVALID_HANDLE_VALUE )
  15. {
  16. printf( "Cannot open TestFile\n" );
  17. return;
  18. }
  19. else
  20. {
  21. WriteFile( hFile, // Handle
  22. "This is TestFile", // Data to be written
  23. 16, // Size of data, in bytes
  24. &dwRet, // Number of bytes written
  25. NULL ); // OVERLAPPED pointer
  26. CloseHandle( hFile );
  27. hFile = INVALID_HANDLE_VALUE;
  28. }
  29. hStream = CreateFile( TEXT("TestFile:Stream"), // Filename
  30. GENERIC_WRITE, // Desired access
  31. FILE_SHARE_WRITE, // Share flags
  32. NULL, // Security Attributes
  33. OPEN_ALWAYS, // Creation Disposition
  34. 0, // Flags and Attributes
  35. NULL ); // OVERLAPPED pointer
  36. if( hStream == INVALID_HANDLE_VALUE )
  37. printf( "Cannot open TestFile:Stream\n" );
  38. else
  39. {
  40. WriteFile( hStream, // Handle
  41. "This is TestFile:Stream", // Data to be written
  42. 23, // Size of data
  43. &dwRet, // Number of bytes written
  44. NULL); // OVERLAPPED pointer
  45. CloseHandle( hStream );
  46. hStream = INVALID_HANDLE_VALUE;
  47. }
  48. }

If you type Type TestFile at a command prompt, it displays the following output:

syntaxCopy

This is TestFile

However, if you type the words Type TestFile:Stream, it generates the following error:

"The filename, directory name, or volume label syntax is incorrect."

To view what is in TestFile:stream, use one of the following commands:

More < TestFile:Stream

More < TestFile:Stream:$DATA

The text displayed is as follows:

syntaxCopy

This is TestFile:Stream
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/367333
推荐阅读
相关标签
  

闽ICP备14008679号