Thread: Resolving Hostname :: MFC

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Resolving Hostname :: MFC

    Hi.

    I am working on a simple program that resolves hostname. Here is the concept:

    Enter hostname: www.google.com
    Resolve IP: 216.239.33.101

    The program has a dialog box for the user to enter the hostname such as (www.google.com or www.yahoo.com).
    Here is the function that does it:

    -----
    void CDomainDNS::resolveHost(const CString &rHName)
    {
    WSAData wData;

    if (WSAStartup(MAKEWORD(2,2), &wData) == SOCKET_ERROR)
    {
    CString error;
    error.Format("Error initialization Winsock");
    AfxMessageBox(error);

    return;
    }

    hostent *host = 0;

    host = gethostbyname(rHName);

    if (host == 0)
    mVeri = false;

    else
    {
    mIP = inet_ntoa(*(reinterpret_cast(host->h_addr)));

    mVeri = true;
    }
    }
    -----

    The code above works perfect under Win32 *console*. However, it only outputs my *internal* ip in MFC application mode.

    For example:

    Enter hostname: www.google.com
    Resolve IP: 192.168.0.1

    Is there something I need to change or add when dealing with the code above in Win32 MFC environment? Maybe there is a better tool for resolve hostname via MFC?

    Thanks,
    Kuphryn

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    I did this as an example of a host resolver....it does a bit more than your example so it might be worth a look...

    As to winsock classes in MFC - from what I see they are pretty lame.......and I dont know if they offer this functionality without you having to use the winsock API..........I have only used an MFC socket once......after that I decided to use the API and it was more functional and more straight forward

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks

    The problem was that I did not call UpdateData(TRUE) before passing the hostname to function resolveHost(...).

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  2. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 06:42 PM
  3. Resolving Hostname Using getaddrinfo(...) :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-03-2002, 08:35 PM
  4. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 06:58 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 01:33 AM