In Windows environment:
Embedding an executable (the executable is embedded in a resource file):
Create a resource file with the following:
Code:
#define IDR_MYNEW 1000
IDR_MYNEW MYNEW_EXE DISCARDABLE "C:\\temp\\new.exe"
Compile the resource file: RC myRC.RC
Then: cl my.cpp myRC.res ws2_32.lib
In your my.exe execute the following functions to extract the embedded excecutable:
FindResource (find embedded executable in resource file)
LoadResource
LockResource
//Now copy embedded executable to hard drive
CreateFile
WriteFile
Code for IP address:
Code:
#include <stdio.h>
#include <WinSock.h>
int main(void)
{
WORD wVersionRequested;
WSADATA wsaData;
char hostname[255] = {0};
int iCount = 0;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 1, 1 );
char *ipaddress = NULL;
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
if( gethostname ( hostname, sizeof(hostname)) == 0)
{
printf("hostname: %s\n", hostname);
if((hostinfo = gethostbyname(hostname)) != NULL)
{
while(hostinfo->h_addr_list[iCount])
{
ipaddress = inet_ntoa(*(struct in_addr *)hostinfo->h_addr_list[iCount]);
printf("ipaddress #%d: %s\n", ++iCount, ipaddress);
}
}
}
return 0;
}