1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
BOOL CMaClasse::getTypeAlim (BOOL *p_bSect)
{
BOOL bRet = TRUE;
// si pas de service MonService, quitter
if (! m_bConnected)
{
m_dwLastError = ERROR_OPERATION_ABORTED;
return FALSE;
}
// Creation d'un pipe pour communiquer avec le service MonService
LPCTSTR _PIPE_NAME = LPCTSTR("\\\\.\\pipe\\MonServicePipe");
char Received_Buffer[256];
DWORD BytesRead = 0;
HANDLE hPIPE = CreateNamedPipe( _PIPE_NAME,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE |
PIPE_READMODE_MESSAGE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
256,
256,
10000, //100 00 mseconds timeout
0x00000000 );
DWORD l_dwControl;
// envoie de l'evenement pour indiquer à MonService la demande
l_dwControl = MONSERVICE_CMD_QUERY_TYPE_ALIM;
if (m_bSecured) {
if (! ControlService(m_hService, l_dwControl, &m_ServiceStatus))
{
m_dwLastError = GetLastError();
bRet = FALSE;
}
}
else {
if (! PostMessage(m_hWnd, MONSERVICESIG_SERVICE_CONTROL, l_dwControl, 0))
{
m_dwLastError = GetLastError();
bRet = FALSE;
}
}
// Attendre que le postmessage soit passé
//Sleep(1000);
// lire la réponse
if ( hPIPE != INVALID_HANDLE_VALUE && bRet == TRUE)
{
int Connected = 0;
Connected = ConnectNamedPipe( hPIPE, NULL );
m_dwLastError = GetLastError();
if ( (Connected != 0) || (m_dwLastError == ERROR_PIPE_CONNECTED))
{
BOOL bRead = ReadFile(hPIPE, Received_Buffer, 256, &BytesRead, NULL );
if ( bRead != 0 )
{
// MessageBox( NULL, Received_Buffer, "Recieved Text!", MB_OK );
m_iTypeAlim = atoi(Received_Buffer);
}
}
else
{
// MessageBox( NULL,"ConnectedNamePipe() Failed.", "Error!", MB_OK );
bRet = FALSE;
}
}
else
{
// MessageBox( NULL, " SERVER FAILED ON CreateNamedPipe()", "ERROR!", MB_OK );
bRet = FALSE;
}
DisconnectNamedPipe(hPIPE);
CloseHandle(hPIPE);
*p_bSect = m_iTypeAlim;
return bRet;
} |
Partager