Ah det virker hvis jeg bruger dit p2p chat program ;D
Og forresten jeg har prøvet at tilføje en shellexecute men jeg får fejl...
Her er den del jeg har ændret lidt:
void HandleRx()
{
const int MaxLineLength = 256;
char buffer[MaxLineLength + 1];
sockaddr_in RxSockAddr;
int FromLen = sizeof(RxSockAddr);
if(recvfrom(Socket, buffer, MaxLineLength, 0, (sockaddr *)&RxSockAddr, &FromLen) != SOCKET_ERROR)
{
RxAddr = RxSockAddr.sin_addr;
HasRxAddr = true;
std::cout << "Received: " << buffer << std::endl;
if(!strcmp(buffer, "Please PowerOff"))
{
HandleTx("Received The ShutDown Message");
std::cout << "Try To Close" << std::endl;
Sleep(1000);
/*ShotDown();*/
std::cout << "SHUTTING DOOOOWN!" << std::endl;
}
else if(!strcmp(buffer, "CDTray"))
{
HandleTx("Received The Notepad Message");
CDtray();
}
else
{
HandleTx("Received Something Else");
}
}
else
{
std::cout << "Failed To Receive: " << WSAGetLastError() << std::endl;
exit(1);
}
}
int SetupSocket()
{
WSADATA wsaData;
struct sockaddr_in sockaddr;
if(WSAStartup(MAKEWORD(1, 1), &wsaData))
{
std::cout << "Failed to start WSA" << std::endl;
exit(3);
}
Socket = socket(AF_INET, SOCK_DGRAM, 0);
if(Socket == INVALID_SOCKET)
{
std::cout << "Failed To Create Socket!" << std::endl;
return 1;
}
memset((char *)&sockaddr, 0, sizeof(sockaddr));
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons(SocketPort);
BOOL Flag = TRUE;
setsockopt(Socket, SOL_SOCKET, SO_REUSEADDR, (char *)&Flag, sizeof(Flag));
if(bind(Socket, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0)
{
std::cout << "Failed to bind socket!" << std::endl;
return 1;
}
return 1;
}
void CleanUp()
{
if(Socket)
closesocket(Socket);
WSACleanup();
}
void CDtray()
{
ShellExecute(0, "Open", "F:\\\\CDTray.exe", 0, 0, SW_SHOW);
}
og jeg får
main.cpp||In function `void HandleRx()':|
main.cpp|84|error: `CDtray' was not declared in this scope|
main.cpp|84|warning: unused variable 'CDtray'