00001
00007 #include "StdAfx.h"
00008 #include "process.h"
00009 #include "..\win2vcc\cmnhdr.h"
00010
00011 #define CLIENTNAME TEXT("Client0")
00012
00013 BYTE palette0[256*3];
00014 BYTE screen0[240*320];
00015
00016 BYTE palette1[256*3];
00017 BYTE screen1[240*320];
00018
00019 MouseClient mouseIn( CLIENTNAME );
00020 ScreenClient screenOut( CLIENTNAME );
00021
00022 DWORD WINAPI screenThread(LPVOID);
00023
00025 int APIENTRY WinMain(HINSTANCE hInstance,
00026 HINSTANCE hPrevInstance,
00027 LPSTR lpCmdLine,
00028 int nCmdShow)
00029
00030 {
00031 AllocConsole();
00032 HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
00033 SetConsoleTitle(TEXT("VCC pipe IO Stub"));
00034
00035
00036
00037 int i;
00038 for(i=0; i<256*3;){
00039 palette0[i] = i % 256;
00040 i++;
00041 palette0[i] = i % 128;
00042 i++;
00043 palette0[i] = (i % 60) * 4;
00044 i++;
00045 }
00046
00047 for(i=0; i<240*320; i++){
00048 screen0[i] = i % 256;
00049 }
00050
00051
00052 srand( (unsigned)time( NULL ) );
00053 for(i=0; i<256*3;){
00054 palette1[i] = rand() % 256;
00055 i++;
00056 palette1[i] = rand() % 128 + 64;
00057 i++;
00058 palette1[i] = i % 256;
00059 i++;
00060 }
00061
00062 for(i=0; i<240*320; i++){
00063 screen1[i] = rand() % 256;
00064 }
00065
00066 CHString msgString;
00067
00068 switch( mouseIn.connect() ){
00069 case PC_ALREADY_CONNECTED:
00070 case PC_CONNECTED:
00071 msgString.Format(TEXT("Mouse Connected\n"));
00072 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00073 break;
00074 case PC_FAILED:
00075 msgString.Format(TEXT("Error Connecting Mouse\nExit in 4 seconds\n"));
00076 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00077 Sleep(4000);
00078 return 1;
00079 break;
00080 case PC_BUSY:
00081 msgString.Format(TEXT("Error - Mouse Pipe already connected\nExit in 4 seconds\n"));
00082 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00083 Sleep(4000);
00084 return 1;
00085 break;
00086 }
00087
00088 switch( screenOut.connect() ){
00089 case PC_ALREADY_CONNECTED:
00090 case PC_CONNECTED:
00091 msgString.Format(TEXT("Screen Connected\n"));
00092 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00093 break;
00094 case PC_FAILED:
00095 msgString.Format(TEXT("Error Connecting Screen\nExit in 4 seconds\n"));
00096 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00097 Sleep(4000);
00098 return 1;
00099 break;
00100 case PC_BUSY:
00101 msgString.Format(TEXT("Error - Screen Pipe already connected\nExit in 4 seconds\n"));
00102 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00103 Sleep(4000);
00104 return 1;
00105 break;
00106 }
00107
00108
00109 chBEGINTHREADEX(NULL, 0, &screenThread, NULL, 0, NULL);
00110
00111 mouseMessage msg;
00112 bool exit = false;
00113 for(i = 1; i>0 && !exit;){
00114 switch( mouseIn.deQueueMessage(&msg) ){
00115 case MI_SUCCESS:
00116 msgString.Format(TEXT("%d: {%.3i,%.3i} %i\n"), i++, msg.x, msg.y, msg.button);
00117 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00118 if( i % 9 == 0 ){
00119 Sleep(1000);
00120 }
00121 break;
00122 case MI_NO_MESSAGE:
00123 Sleep(100);
00124 break;
00125 case MI_NOT_CONNECTED:
00126 msgString.Format(TEXT("Server Disconnected\n"));
00127 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00128 case MI_UNKNOWN_ERROR:
00129 default:
00130 msgString.Format(TEXT("Error getting Message\n"));
00131 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00132 Sleep(5000);
00133 exit = true;
00134 }
00135 }
00136
00137 mouseIn.disconnect();
00138 screenOut.disconnect();
00139
00140 FreeConsole();
00141 CloseHandle(console);
00142 return 0;
00143 }
00144
00146 DWORD WINAPI screenThread(LPVOID)
00147 {
00148 while( true ){
00149 if(!screenOut.write(240, 320, 256, 8, (RGBTRIPLE*) palette0, screen0))
00150 break;
00151 Sleep(1000);
00152
00153 if(!screenOut.write(240, 320, 256, 8, (RGBTRIPLE*) palette1, screen1))
00154 break;
00155 Sleep(1000);
00156
00157 if(!screenOut.write(240, 320, 256, 8, (RGBTRIPLE*) palette0, screen1))
00158 break;
00159 Sleep(1000);
00160
00161 if(!screenOut.write(240, 320, 256, 8, (RGBTRIPLE*) palette1, screen0))
00162 break;
00163 Sleep(1000);
00164 }
00165 HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
00166 CHString msgString;
00167 msgString.Format(TEXT("\nSCREEN DIDN'T WRITE\n"));
00168 WriteConsole(console, msgString, msgString.GetLength(), NULL, NULL);
00169
00170 return true;
00171 }