до pipe на клієнті "," Помилка ", MB_OK + MB_ICONHAND);
Application-> Terminate ();
}
char * StrPered = DannieToChar (0, KolKub, MaxOch);
PipeSend (strPered);
InterfaceBeginNewGame ();
ChangeInterfacePerehodHoda (1);
}
else
{
if (IsVisitApplicationBox) return;
Priem (CharToMas (Buf));
}
}
}
}
// ----------------- відправка --------------------------- --------------------------
void __ fastcall TMainForm :: PipeSend (Char * Buf)
{
unsigned long cbWritten = 0;
WriteFile (PipeSendHandle, Buf, strlen (Buf) +1, & cbWritten, NULL);
}
// ------------------- розрив з'єднання -----------------------------------------
void __ fastcall TMainForm :: PipeCloseConnection (void)
{
CloseHandle (PipeSendHandle);
CloseHandle (PipeReceiveHandle);
TimerPipe-> Enabled = false;
}
Mailslot.cpp
// --------------------------------------------- ------------------------------
# pragma hdrstop
# include
# include
# include
# include "MailSlot.h"
# include "Podkluch.h"
# include "Main.h"
// --------------------------------------------- ---------------------------------
# pragma package (smart_init)
HANDLE ReceiveMailslotHandle, SendMailslotHandle;
int HisPrevNomMessage = 0;
int MyCurrNomMessage = 0;
extern bool IsServer;
extern AnsiString ServerHostName;
extern int KolKub;
extern int MaxOch;
// ----------------------- підключення --------------------- -----------------------
void __ fastcall TMainForm :: MailSlotConnect (void)
{
if (IsServer)
{
ReceiveMailslotHandle = CreateMailslot (" . Mailslot msserver", 0, MAILSLOT_WAIT_FOREVER, NULL);
if (ReceiveMailslotHandle == INVALID_HANDLE_VALUE)
{
Application-> MessageBox ("Помилка при створенні mailslot "," Помилка ", MB_OK + MB_ICONHAND);
Application-> Terminate ();
}
TimerMailSlot-> Enabled = true;
}
else
{
ReceiveMailslotHandle = CreateMailslot (" . Mailslot msclient", 0, MAILSLOT_WAIT_FOREVER, NULL);
if (ReceiveMailslotHandle == INVALID_HANDLE_VALUE)
{
Application-> MessageBox ("Помилка при створенні mailslot "," Помилка ", MB_OK + MB_ICONHAND);
Application-> Terminate ();
}
TimerMailSlot-> Enabled = true;
char BufConnect [70];
sprintf (BufConnect, " % s mailslot msserver" , ServerHostName.c_str ());
SendMailslotHandle = CreateFile (BufConnect, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (SendMailslotHandle == INVALID_HANDLE_VALUE)
{
Application-> MessageBox ("Помилка при відкритті mailslot "," Помилка ", MB_OK + MB_ICONHAND);
Application-> Terminate ();
}
char CompName [50];
unsigned long cnl = 50;
GetComputerName (CompName, & Cnl);
int i = StrLen (CompName);
if (i> = 50)
{
CompName [49] = ' 0';
}
unsigned long cbWritten;
char BufExchange [50];
MyCurrNomMessage = 1;
strcpy (BufExchange, "1;");
strcat (BufExchange, CompName);
WriteFile (SendMailslotHandle, BufExchange, strlen (BufExchange) +1, & CbWritten, NULL);
}
}
// ----------------------- прийом і accept -----------------------------------------
void __ fastcall TMainForm :: TimerMailSlotTimer (TObject * Sender)
{
if (IsVisitApplicationBox) return;
int rc;
unsigned long cbMessages, cbMsgNumber, cbRead;
char * BufExchange;
rc = GetMailslotInfo (ReceiveMailslotHandle, NULL, & cbMessages, & cbMsgNumber, NULL);
if (! rc)
{
Application-> MessageBox ("Помилка GetMailslotInfo "," Помилка ", MB_OK + MB_ICONHAND);
Application-> Terminate ();
}
if (cbMsgNumber == 0) return;
BufExchange = new char [cbMessages];
ZeroMemory (BufExchange, cbMessages);
if (ReadFile (ReceiveMailslotHandle, BufExchange, cbMessages, & cbRead, NULL))
{
int HisCurrNomMessage;
char Buftmp [150];
strcpy (Buftmp, BufExchange);
HisCurrNomMessage = atoi (strtok (BufExchange, ";"));
if (HisCurrNomMessage> HisPrevNomMessage)
{
HisPrevNomMessage = HisCurrNomMessage;
char * Buf;
Buf = AnsiStrScan (Buftmp, ';');
Buf + +;
if (IsServer && HisCurrNomMessage == 1)
{
char BufConnect [100];
sprintf (BufConnect, " ...