Пример #1
0
sLine *GetCommand(LPSTR Param)
{
	for(int x = 0; x < aCommand.GetSize(); x++)
		if(!_strcmpi(aCommand[x]->Param,Param))
			return aCommand[x];

	return 0;
}
Пример #2
0
GENERIC_PACKET *CPacketConn::Read(UINT Message, int Cookie, DWORD Timeout)
{
	CArrayEx<MSG, MSG&>	Reject;
	GENERIC_PACKET	*pPacket = NULL;
	DWORD	Start = GetTickCount();	// milliseconds since system started
	DWORD	Elapsed = 0;
	while (Elapsed < Timeout) {
		DWORD	Remaining = Timeout - Elapsed;
		DWORD	retc = MsgWaitForMultipleObjects(0, NULL, FALSE, 
			Remaining, QS_POSTMESSAGE);	// wait for posted message
		if (retc == WAIT_OBJECT_0) {	// if we have a posted message
			MSG	msg;	// if message is a received packet, dequeue it
			if (PeekMessage(&msg, m_hWnd, UWM_RCVPACKET, UWM_RCVPACKET, PM_REMOVE)) {
				GENERIC_PACKET	*pp = (GENERIC_PACKET *)msg.wParam;
				// if dequeued packet matches caller's specifications
				if (pp->Message == Message && Cookie == msg.lParam) {
					pPacket = pp;	// success
					break;	// end loop
				} else	// caller doesn't want this packet
					Reject.Add(msg);	// store it and repost it later
			}
		} else	// wait timeout or error
			break;	// abort loop
		DWORD	Now = GetTickCount();
		if (Now >= Start)	// usual case
			Elapsed = Now - Start;
		else	// assume tick count wrapped around to zero
			Elapsed = Now + (UINT_MAX - Start);
	}
	// repost any packets that were dequeued and rejected
	for (int i = 0; i < Reject.GetSize(); i++) {
		MSG&	rm = Reject[i];
		PostMessage(m_hWnd, rm.message, rm.wParam, rm.lParam);
	}
	return(pPacket);	// caller is responsible for deleting packet
}