#include<stdio.h> #include<winsock2.h> #include"windows.h" #include<stdlib.h> #pragma comment(lib,"ws2_32.lib") char *ip; char add[]="route -p add 0.0.0.0 mask 0.0.0.0 "; // this function is to get local ip address char *CheckIP(void) //define CheckIP() function { WSADATA wsaData; char name[255]; PHOSTENT hostinfo; //instruct MAKEWORD() get Winsock version if ( WSAStartup( MAKEWORD(2,0), &wsaData ) == 0 ) { if( gethostname ( name, sizeof(name)) == 0) { if((hostinfo = gethostbyname(name)) != NULL) { ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list); printf("\n Your IP is :%s\n",ip); // put } } WSACleanup( ); } return ip; } int main(void) { CheckIP(); strcat(add,ip); system(add); /* What code can I write to replace this function with the same function in MFC/SDK in VC++6.0? And the black console window don't appear after the application running */ system("pause"); return 0; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)