CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

W95TRACE.CPP (3967B)


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