Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:27:48+00:00 2026-06-14T04:27:48+00:00

Good afternoon. I’ve started learning c++ and I am having and issue compiling my

  • 0

Good afternoon. I’ve started learning c++ and I am having and issue compiling my project.
If you find some faulty code I would be glad if you tell me.

I have the following definitions:

Utils.h

#include "stdafx.h"
#include <string>
using namespace std;

class Utils
{
public:
static string GetStringFromInt (int number);
};

Utils.cpp

#include "Utils.h"
#include <sstream>
#include <string>
using namespace std;

 string Utils::GetStringFromInt (int number)
{

    stringstream ss;
    ss << number;
    return ss.str();
}

and

Ping.h

#include "stdafx.h"
#include <string>

using namespace std;

class Ping
{
public:
    static int PingIt(int argc, char* argv[],string &mstime,string &ttl);   
};

Ping.cpp

#include "Ping.h"
#include <string>
#include "icmpdefs.h"
#include <string>
#include <iostream>
#include <sstream>
#include <WinSock.h>
#include <Windows.h>
#include "Utils.h"
#pragma comment(lib,"wsock32.lib")
using namespace std;

int Ping::PingIt(int argc, char* argv[],string &mstime,string &ttl)
{


    // Check for correct command-line args
    if (argc < 2) {
        cerr << "usage: ping <host>" << endl;
        return 1;
    }

    // Load the ICMP.DLL
    HINSTANCE hIcmp = LoadLibrary("ICMP.DLL");
    if (hIcmp == 0) {
        cerr << "Unable to locate ICMP.DLL!" << endl;
        return 2;
    }

    // Look up an IP address for the given host name
    struct hostent* phe;
    if ((phe = gethostbyname(argv[1])) == 0) {
        cerr << "Could not find IP address for " << argv[1] << endl;
        return 3;
    }

    // Get handles to the functions inside ICMP.DLL that we'll need
    typedef HANDLE (WINAPI* pfnHV)(VOID);
    typedef BOOL (WINAPI* pfnBH)(HANDLE);
    typedef DWORD (WINAPI* pfnDHDPWPipPDD)(HANDLE, DWORD, LPVOID, WORD,
            PIP_OPTION_INFORMATION, LPVOID, DWORD, DWORD); // evil, no?
    pfnHV pIcmpCreateFile;
    pfnBH pIcmpCloseHandle;
    pfnDHDPWPipPDD pIcmpSendEcho;
    pIcmpCreateFile = (pfnHV)GetProcAddress(hIcmp,
            "IcmpCreateFile");
    pIcmpCloseHandle = (pfnBH)GetProcAddress(hIcmp,
            "IcmpCloseHandle");
    pIcmpSendEcho = (pfnDHDPWPipPDD)GetProcAddress(hIcmp,
            "IcmpSendEcho");
    if ((pIcmpCreateFile == 0) || (pIcmpCloseHandle == 0) || 
            (pIcmpSendEcho == 0)) {
        cerr << "Failed to get proc addr for function." << endl;
        return 4;
    }

    // Open the ping service
    HANDLE hIP = pIcmpCreateFile();
    if (hIP == INVALID_HANDLE_VALUE) {
        cerr << "Unable to open ping service." << endl;
        return 5;
    }

    // Build ping packet
    char acPingBuffer[64];
    memset(acPingBuffer, '\xAA', sizeof(acPingBuffer));
    PIP_ECHO_REPLY pIpe = (PIP_ECHO_REPLY)GlobalAlloc(
            GMEM_FIXED | GMEM_ZEROINIT,
            sizeof(IP_ECHO_REPLY) + sizeof(acPingBuffer));
    if (pIpe == 0) {
        cerr << "Failed to allocate global ping packet buffer." << endl;
        return 6;
    }
    pIpe->Data = acPingBuffer;
    pIpe->DataSize = sizeof(acPingBuffer);      

    // Send the ping packet
    DWORD dwStatus = pIcmpSendEcho(hIP, *((DWORD*)phe->h_addr_list[0]), 
            acPingBuffer, sizeof(acPingBuffer), NULL, pIpe, 
            sizeof(IP_ECHO_REPLY) + sizeof(acPingBuffer), 5000);
    if (dwStatus != 0) {
        cout << "Addr: " <<
                int(LOBYTE(LOWORD(pIpe->Address))) << "." <<
                int(HIBYTE(LOWORD(pIpe->Address))) << "." <<
                int(LOBYTE(HIWORD(pIpe->Address))) << "." <<
                int(HIBYTE(HIWORD(pIpe->Address))) << ", " <<
                "RTT: " << int(pIpe->RoundTripTime) << "ms, " <<
                "TTL: " << int(pIpe->Options.Ttl) << endl;

        mstime = Utils::GetStringFromInt((pIpe->RoundTripTime));
        ttl = Utils::GetStringFromInt(int(pIpe->Options.Ttl));
    }
    else {
        cerr << "Error obtaining info from ping packet." << endl;
    }

    // Shut down...
    GlobalFree(pIpe);
    FreeLibrary(hIcmp);
    return dwStatus;
}

When I Compile the project I get:

Error 1 error C2653: ‘Ping’ : is not a class or namespace name c:\users\clanderasm\documents\visual studio 2010\projects\landetestconsole\landecplusconsole\ping.cpp 14 1 LandeCplusConsole

I’ve read sometimes this error is thrown because you dont include “stdafx.h”
on the first #include but I already changed it.

If you could tell me something more I would be glad

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:27:49+00:00Added an answer on June 14, 2026 at 4:27 am

    I couldn’t reproduce your error with the code you gave, but I tried on VS2008 and some of the warning it raised make me think it could very much be due to your precompiled header not being included in sources. And there is a couple of other problems I can see that will surely cause you problems later:

    • Don’t include precompiled header in .h. (Well you should even avoid including anything in your .h unless absolutely necessary). The precompiled header (at least in visual way of doing things) is meant to be included first in each cpp files (not .h). If you don’t do so it will raise warnings for each includes you have like:

      warning C4627: ‘#include “Ping.h”‘: skipped when looking for precompiled header use <- here you go your Point class is no longer defined!

      and finally an error fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add ‘#include “stdafx.h”‘ to your source?.

      It’s actually messages I get when compiling your code on VS2008, maybe on VS2010 you have your error about Point not being defined in addition to those. When sorting out precompiled header problems it compiles fine (see next point)

    • Using a precompiled header does not mean the .h used to build it will be automatically included in all your sources. To do so, you have to change some project setting: right click on your project -> Properties, in the left panel, expand Configuration Properties -> C/C++ -> Advanced. Here on the list on the right you should see Force Includes. Type here stdafx.h, and voilà, you won’t have to put it manually in each and every new .cpp you add to your project. Beware that you have to do that for all configuration (combo box on the top written “Configuration : Active(Debug)”

    Apologies, still a VS2008 screen, hope it’s the same on VS2010
    enter image description here

    • Guard your headers. You should put gards on your headers to avoid multiple definitions of your classes when multiple include of the same .h happens (and it will).
      You can do it 2 ways: the define method, and the pragma once method.
      The pragma once is not standard but compiles faster on Visual, so you can eventually mix the 2 ways.

    myheader.h using pragma once:

    #pragma once
    class MyClass
    {
        //<some definitions>
    };
    

    myheader.h using defines:

    #ifndef __MYHEADER_H
    #define __MYHEADER_H
    class MyClass
    {
        //<some definitions>
    };
    #endif
    

    myheader.h using both:

    #pragma once
    #ifndef __MYHEADER_H
    #define __MYHEADER_H
    class MyClass
    {
        //<some definitions>
    };
    #endif
    
    • It has already been said, but avoid the use of “using” in headers because it will spread. I myself avoid the use of “using” everywhere.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good afternoon, I'm having a problem with a section of code I'm working on
Good afternoon, I am having an issue with wordpress. I access to page123.domain.com and
Good afternoon! I have some doubts about following code. [1] What does the middle
Good afternoon, I would ask some suggestion about the best way to monitor events
Good Afternoon, everyone. I have an ongoing issue with the code below. I know
Good afternoon, hope someone can shed some light on a strange issue that I
Good afternoon, I'm having serious troubles getting my database back up and running. I
Good afternoon, I've run into some issues trying to combine HTTP caching with Rack::Cache
Good afternoon, I am currently in the very early phase of a new project
Good afternoon, I'm working on a project for my company to run an update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.