Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,everyone,
I wrote a console app..But it's not beautiful, I want to turn it into MFC/SDK application in VC6.0. the code is as follow:

C++
#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;
}

Could someone help me? Show me your code.
Thanks in advance.
Posted
Updated 21-Jun-10 13:17pm
v8

hi create a win32 or MFC APP using Microsoft Visual studio. create a button and a text box using CreateWindow API.

on the WM_CREATE: write your logic to find the Ip address and display in the Text Box or Create a button event to display your output in the Text Box
 
Share this answer
 
Comments
eagle_chen 20-Jun-10 0:37am    
Thanks!but in this code: system(add) ... What code can I write with the same funcion in MFC/SDK?
Start a new MFC application in Visual Studio, and copy your code into it in the appropriate place(s).
 
Share this answer
 
Assuming that you have a version of Visual Studio or Visual C++ that supports MFC then you can use the New Project wizard to create a basic MFC sample and add your own code as appropriate. There are many samples available on the MSDN site to help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900