Source code of Windows XP (NT5)
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.

65 lines
1.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. SimpleFp.h
  5. Abstract:
  6. simple FILE*, instead of msvcrt.dll
  7. Author:
  8. Xiaoyu Wu(xiaoyuw) July 2000
  9. Revision History:
  10. --*/
  11. #pragma once
  12. #include <stdio.h>
  13. class CSimpleFileStream
  14. {
  15. public:
  16. HRESULT fopen(PCSTR pFileName); // can be a file name, "stderr", "stdout"
  17. HRESULT fclose();
  18. static HRESULT printf(const WCHAR *format, ...)
  19. {
  20. HRESULT hr = NOERROR;
  21. va_list ap;
  22. WCHAR rgchBuffer[2048];
  23. int cch;
  24. DWORD cchWritten;
  25. va_start(ap, format);
  26. cch = _vsnwprintf(rgchBuffer, NUMBER_OF(rgchBuffer), format, ap);
  27. rgchBuffer[NUMBER_OF(rgchBuffer) - 1] = 0;
  28. va_end(ap);
  29. if (cch < 0) {// error case
  30. hr = E_UNEXPECTED;
  31. goto Exit;
  32. }
  33. if( !WriteConsole(GetStdHandle(STD_ERROR_HANDLE), rgchBuffer, cch, &cchWritten, NULL)){
  34. DWORD dwError = ::FusionpGetLastWin32Error();
  35. hr = HRESULT_FROM_WIN32(dwError);
  36. goto Exit;
  37. }
  38. hr = NOERROR;
  39. Exit :
  40. return hr;
  41. }
  42. HRESULT fprintf(const char *format, ...);
  43. HRESULT fwrite(const VOID*, SIZE_T, SIZE_T);
  44. CSimpleFileStream(PCSTR pFileName);
  45. ~CSimpleFileStream();
  46. private:
  47. HANDLE m_hFile;
  48. };