W95TRACE.CPP 3.8 KB

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