C++ 智能感知:错误C2440:&x27=';:无法从';无符号长(u stdcall*)(const char*)&x27;至';IPAddr';
我试图编写一个应用程序,ping一个ip地址,并提供与ping相关的信息。当我遇到过多的错误时,我选择先尝试并学习解决这个错误!我有一小段代码和一个单独的文档,其中包含编译器错误。如果有人能把这个错误翻译成英语,那就太棒了。我觉得如果我处理好了底部的两个错误,那么其他很多错误可能会更容易确定。提前谢谢C++ 智能感知:错误C2440:&x27=';:无法从';无符号长(u stdcall*)(const char*)&x27;至';IPAddr';,c++,visual-studio,intellisense,ping,icmp,C++,Visual Studio,Intellisense,Ping,Icmp,我试图编写一个应用程序,ping一个ip地址,并提供与ping相关的信息。当我遇到过多的错误时,我选择先尝试并学习解决这个错误!我有一小段代码和一个单独的文档,其中包含编译器错误。如果有人能把这个错误翻译成英语,那就太棒了。我觉得如果我处理好了底部的两个错误,那么其他很多错误可能会更容易确定。提前谢谢 #include <iostream> #include <stdio.h> #include <Windows.h> #include <iphlpap
#include <iostream>
#include <stdio.h>
#include <Windows.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <string>
#include <winsock2.h>
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
using namespace std;
void CreateIcmpHandle(HANDLE &TheHdl){
TheHdl = IcmpCreateFile();
}
char* Getdestination(){
char* theaddress;
cout << "Where do you want to check? Enter the IP: ";
cin >> theaddress;
return theaddress;
}
void main(){
HANDLE MyHandle;
const char *theaddress;
char Randomdata[30] = "Stuff to send away!";
DWORD mainint,lenofbuffer;
void* bufferpointer = NULL;
ICMP_ECHO_REPLY* reply; //pointer to an ICMP_ECHO_REPLY data structure
IPAddr address;
lenofbuffer = strlen(Randomdata) + sizeof(ICMP4_ECHO_REPLY) + 1; //Make buffer large enough to contain data sent and the size of the ICMP_ECHO_REPLY data structure
bufferpointer = malloc(lenofbuffer); //allocates a block of memory with number of bits of lenofbuffer
memset(bufferpointer,0,lenofbuffer); //puts the previously allocated block in memory and writes lenofbuffer # of 0's
reply = (ICMP_ECHO_REPLY*)bufferpointer;
CreateIcmpHandle(MyHandle);
theaddress = Getdestination();
address = inet_addr(theaddress);
mainint = IcmpSendEcho(MyHandle, address, Randomdata, strlen(Randomdata), NULL, bufferpointer, lenofbuffer, 2000); //Returns the number of replies from theaddress
if(mainint = IP_SUCCESS){ //If the status of the ICMP_ECHO_REPLY structures stored in bufferpointer is IP_SUCCESS
cout<<"Success! The ping returned "<< mainint <<" message replies from "<<reply->Address<<endl;
cout<<"It took "<<reply->RoundTripTime<<" milliseconds."<<endl;
}
IcmpCloseHandle(MyHandle);
}
这是你的问题:
#include <Windows.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <string>
#include <winsock2.h>
#包括
#包括
#包括
#包括
#包括
您必须首先包括winsock2.h,否则windows.h将包括winsock.h
试一试
#包括
#包括
#包括
#包括
#包括
这是您的问题:
#include <Windows.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <string>
#include <winsock2.h>
#包括
#包括
#包括
#包括
#包括
您必须首先包括winsock2.h,否则windows.h将包括winsock.h
试一试
#包括
#包括
#包括
#包括
#包括
这是您的问题:
#include <Windows.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <string>
#include <winsock2.h>
#包括
#包括
#包括
#包括
#包括
您必须首先包括winsock2.h,否则windows.h将包括winsock.h
试一试
#包括
#包括
#包括
#包括
#包括
这是您的问题:
#include <Windows.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <string>
#include <winsock2.h>
#包括
#包括
#包括
#包括
#包括
您必须首先包括winsock2.h,否则windows.h将包括winsock.h
试一试
#包括
#包括
#包括
#包括
#包括
如果将winsock2.h
include移动到windows.h
上,会发生什么情况?我似乎记得默认情况下包含了过时的WinSock 1定义。这不是您要求的,但Getdestination将崩溃。是的,我仍然有这个问题。如果我将其更改为返回字符串,inet_addr必须是const char*。我不知道如何解决这个错误,我无法将字符串转换为指针。我可以创建一个指向字符串对象的指针,并将其用作inet_addr的参数吗?@CraigSmith:Tryinet_addr(some_string.c_str())
噢,很酷,这个方法似乎就是为了这个问题而创建的。如果将winsock2.h
include移到windows.h
上面,会发生什么?我似乎记得默认情况下包含了过时的WinSock 1定义。这不是您要求的,但Getdestination将崩溃。是的,我仍然有这个问题。如果我将其更改为返回字符串,inet_addr必须是const char*。我不知道如何解决这个错误,我无法将字符串转换为指针。我可以创建一个指向字符串对象的指针,并将其用作inet_addr的参数吗?@CraigSmith:Tryinet_addr(some_string.c_str())
噢,很酷,这个方法似乎就是为了这个问题而创建的。如果将winsock2.h
include移到windows.h
上面,会发生什么?我似乎记得默认情况下包含了过时的WinSock 1定义。这不是您要求的,但Getdestination将崩溃。是的,我仍然有这个问题。如果我将其更改为返回字符串,inet_addr必须是const char*。我不知道如何解决这个错误,我无法将字符串转换为指针。我可以创建一个指向字符串对象的指针,并将其用作inet_addr的参数吗?@CraigSmith:Tryinet_addr(some_string.c_str())
噢,很酷,这个方法似乎就是为了这个问题而创建的。如果将winsock2.h
include移到windows.h
上面,会发生什么?我似乎记得默认情况下包含了过时的WinSock 1定义。这不是您要求的,但Getdestination将崩溃。是的,我仍然有这个问题。如果我将其更改为返回字符串,inet_addr必须是const char*。我不知道如何解决这个错误,我无法将字符串转换为指针。我可以创建一个指向字符串对象的指针并将其用作inet\u addr的参数吗?@CraigSmith:Tryinet\u addr(some\u string.c\u str())
Oh cool,这个方法似乎就是为这个问题创建的。哇,这么简单的错误。我不知道这是个问题,我以后会记住的。谢谢哇,这么简单的错误。我不知道这是个问题,我以后会记住的。谢谢哇,这么简单的错误。我不知道这是个问题,我以后会记住的。谢谢哇,这么简单的错误。我不知道这是个问题,我以后会记住的。谢谢