W95TRACE.CPP 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /*
  15. Implementation of Win95 tracing facility to mimic that of NT
  16. */
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include <stdarg.h>
  20. #include <process.h>
  21. #include "w95trace.h"
  22. void OutputDebugStringW95( LPCTSTR /*lpOutputString*/, ...)
  23. {
  24. #if 0
  25. HANDLE heventDBWIN; /* DBWIN32 synchronization object */
  26. HANDLE heventData; /* data passing synch object */
  27. HANDLE hSharedFile; /* memory mapped file shared data */
  28. LPSTR lpszSharedMem;
  29. char achBuffer[500];
  30. /* create the output buffer */
  31. va_list args;
  32. va_start(args, lpOutputString);
  33. vsprintf(achBuffer, lpOutputString, args);
  34. va_end(args);
  35. achBuffer[499] = 0; // Null-terminate here, just in case vsprintf didn't do it because lpOutputString was too long.
  36. /*
  37. Do a regular OutputDebugString so that the output is
  38. still seen in the debugger window if it exists.
  39. This ifdef is necessary to avoid infinite recursion
  40. from the inclusion of W95TRACE.H
  41. */
  42. #ifdef _UNICODE
  43. ::OutputDebugStringW(achBuffer);
  44. #else
  45. ::OutputDebugStringA(achBuffer);
  46. #endif
  47. // added by ajw
  48. //FILE* pFile = fopen( "debugout.wri", "a" );
  49. FILE* pFile = fopen( "wolapi.out", "a" );
  50. fprintf( pFile, achBuffer );
  51. fclose( pFile );
  52. // /* bail if it's not Win95 */
  53. // {
  54. // OSVERSIONINFO VerInfo;
  55. // VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  56. // GetVersionEx(&VerInfo);
  57. // if ( VerInfo.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS )
  58. // return;
  59. // }
  60. /* make sure DBWIN is open and waiting */
  61. heventDBWIN = OpenEvent(EVENT_MODIFY_STATE, FALSE, "DBWIN_BUFFER_READY");
  62. if ( !heventDBWIN )
  63. {
  64. //MessageBox(NULL, "DBWIN_BUFFER_READY nonexistent", NULL, MB_OK);
  65. return;
  66. }
  67. /* get a handle to the data synch object */
  68. heventData = OpenEvent(EVENT_MODIFY_STATE, FALSE, "DBWIN_DATA_READY");
  69. if ( !heventData )
  70. {
  71. // MessageBox(NULL, "DBWIN_DATA_READY nonexistent", NULL, MB_OK);
  72. CloseHandle(heventDBWIN);
  73. return;
  74. }
  75. hSharedFile = CreateFileMapping((HANDLE)-1, NULL, PAGE_READWRITE, 0, 4096, "DBWIN_BUFFER");
  76. if (!hSharedFile)
  77. {
  78. //MessageBox(NULL, "DebugTrace: Unable to create file mapping object DBWIN_BUFFER", "Error", MB_OK);
  79. CloseHandle(heventDBWIN);
  80. CloseHandle(heventData);
  81. return;
  82. }
  83. lpszSharedMem = (LPSTR)MapViewOfFile(hSharedFile, FILE_MAP_WRITE, 0, 0, 512);
  84. if (!lpszSharedMem)
  85. {
  86. //MessageBox(NULL, "DebugTrace: Unable to map shared memory", "Error", MB_OK);
  87. CloseHandle(heventDBWIN);
  88. CloseHandle(heventData);
  89. return;
  90. }
  91. /* wait for buffer event */
  92. WaitForSingleObject(heventDBWIN, INFINITE);
  93. /* write it to the shared memory */
  94. *((LPDWORD)lpszSharedMem) = getpid();
  95. wsprintf(lpszSharedMem + sizeof(DWORD), "%s", achBuffer);
  96. /* signal data ready event */
  97. SetEvent(heventData);
  98. /* clean up handles */
  99. CloseHandle(hSharedFile);
  100. CloseHandle(heventData);
  101. CloseHandle(heventDBWIN);
  102. return;
  103. #endif
  104. }