现在需要 IcmpSendEcho2 的VB声明,可是找了半天,没有找到,只搜到了VC的声明,哪位朋友有VB的声明帮忙贴一下,或者能帮忙翻译一下。谢谢了。
这是微软网站的VC声明 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/icmpsendecho2.asp

解决方案 »

  1.   

    Declare Function IcmpSendEcho2 Lib "Icmpapi.dll" (ByVal IcmpHandle As Long, _
                    ByVal Events As Long, _
                    ByVal ApcRoutine As Long, _
                    ByVal ApcContext As Long, _
                    DestinationAddress As Any, _
                    ByVal RequestData As Long, _
                    ByVal RequestSize As Integer, _
                    ByVal RequestOptions As Long, _
                    ByVal ReplyBuffer As Long, _
                    ByVal ReplySize As Long, _
                    ByVal Timeout As Long)
      

  2.   

    修改一下:Declare Function IcmpSendEcho2 Lib "Icmpapi.dll" (ByVal IcmpHandle As Long, _
                    ByVal Events As Long, _
                    ByVal ApcRoutine As Long, _
                    ByVal ApcContext As Long, _
                    ByVal DestinationAddress As Long, _
                    ByVal RequestData As Long, _
                    ByVal RequestSize As Integer, _
                    ByVal RequestOptions As Long, _
                    ByVal ReplyBuffer As Long, _
                    ByVal ReplySize As Long, _
                    ByVal Timeout As Long)
      

  3.   

    这里有一个IcmpSendEcho方法的调用:http://vbnet.mvps.org/code/internet/ping.htm
    你可以参考一下.
      

  4.   

    如果IcmpSendEcho2是個動態鏈接庫,和其他的動態鏈接是沒有什麼區別的這是聲明VC動態鏈接庫的一個例,請你參考
    Declare Function rf_init Lib "mwrf32.dll" (ByVal port%, ByVal baud As Long) As Long
    Declare Function rf_load_key_hex Lib "mwrf32.dll" (ByVal icdev As Long, ByVal mode%, ByVal secnr%, ByVal nkey As String) As Integer
    Declare Function rf_exit Lib "mwrf32.dll" (ByVal icdev As Long) As Integer
      

  5.   

    试了一下,但是说找不到 Icmpapi.dll 这个文件。我找了一下系统目录,确实没有找到它,我看到系统目录下有 icmp.dll 这个文件,于是改了它,但是调用的时候显示 DLL 调用约定错误
    这该怎么办?
      

  6.   

    你要注冊控件regsvr32 D:\123\Icmpapi.dll
      

  7.   

    開始-->運行-->輸入命令regsvr32 D:\123\Icmpapi.dll-->確定
      

  8.   

    //试了一下,但是说找不到 Icmpapi.dll 这个文件。我找了一下系统目录,确实没有找到它,我看到系统目录下有 icmp.dll 这个文件,于是改了它,但是调用的时候显示 DLL 调用约定错误
    这该怎么办?我不知道你是什么操作系统,我用的2000server中的icmp.dll这个dll文件没有IcmpSendEcho2这个导出函数(IcmpSendEcho函数可用),你还是找找Icmpapi.dll这个文件吧
      

  9.   

    这个函数的定义在 Iphlpapi.dll 里面
      

  10.   

    参考:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/icmpsendecho2.asp
      

  11.   

    IcmpSendEcho2 is available in icmp.dll on Windows 2000; it is available in iphlpapi.dll on later versions of Windows. OS version checking is not recommended. Applications requiring portability with this API across Windows 2000, Windows XP, Windows Server 2003 and later Windows versions should not statically link to either icmp.dll or iphlpapi.dll. A Rather, the application should check for the presence of IcmpSendEcho2 in iphlpapi.dll with calls to LoadLibrary and GetProcAddress. Failing that, the application should check for the presence of IcmpSendEcho2 in icmp.dll with calls to LoadLibrary and GetProcAddress.Windows Me/98/95:  Event, ApcRoutine and ApcContext are ignored.不过,在我的2000server中,无论是icmp.dll 还是iphlpapi.dll 都没有IcmpSendEcho2这个导出函数出现
      

  12.   

    因为有点事情。所以未能及时的回复这个帖子,望各位朋友见谅。
    系统是XP SP2 ,当声明为 icmpapi.dll 的时候是提示没有找到文件。而当声明为 icmp 的时候却提示调用约定错误。
    这说明这个函数确实存在于 icmp.dll 中,只是声明的时候的参数不对。
    还是请各位朋友再指点一下,尤其是 TechnoFantasy(冰儿马甲www.applevb.com) 版主,您看看是不是翻译有误?
      

  13.   

    把RequestOptions声明为结构体试试
      

  14.   

    IcmpSendEcho2的原型如下:
    DWORD IcmpSendEcho2(
      HANDLE IcmpHandle,
      HANDLE Event,
      FARPROC ApcRoutine,
      PVOID ApcContext,
      IPAddr DestinationAddress,
      LPVOID RequestData,
      WORD RequestSize,
      PIP_OPTION_INFORMATION RequestOptions,
      LPVOID ReplyBuffer,
      DWORD ReplySize,
      DWORD Timeout
    );其中3个参数为结构体:1 DestinationAddress 
    [in] Destination of the echo request, in the form of an IPAddr structure. 
    typedef struct {
      union {
        struct {
          u_char s_b1,s_b2,s_b3,s_b4;   
        } S_un_b;
        struct { 
         u_short s_w1,s_w2;
        } S_un_w;
        u_long S_addr;
        } S_un;
     } IPAddr;  
    这个不用理它,不管它怎么折腾,固定占四个字节,定义为long
    2 RequestOptions 
    [in] Pointer to the IP header options for the request, in the form of an IP_OPTION_INFORMATION structure. 
    这个定义为:
    Type IP_OPTION_INFORMATION 
      Ttl         As Byte 'Time To Live
      Tos         As Byte ' Type Of Service
      Flags       As Byte 'IP header flags
      OptionsSize As Byte ' Size in bytes of options data
      OptionsData As Long ' Pointer to options data
    End Type3 ReplyBuffer 
    [out] Buffer to hold any replies to the request. Upon return, the buffer contains an array of ICMP_ECHO_REPLY structures followed by options and data. The buffer must be large enough to hold at least one ICMP_ECHO_REPLY structure. It must be large enough to also hold 9 more bytes of data. 
    这个定义为:
    Type ICMP_ECHO_REPLY
      Address       As Long                  'Replying address
      Status        As Long                  'Reply IP_STATUS
      RoundTripTime As Long                  'RTT in milliseconds
      DataSize      As Integer               'Reply data size in bytes
      Reserved      As Integer               'Reserved for system use
      DataPointer   As Long                  'Pointer to the reply data
      Options       As IP_OPTION_INFORMATION 'Reply options
      Data          As String * MAX_PATH     'Reply data pointed to by "DataPointer"
    End Type其中的Data为缓冲区,要保证它足够大最后,IcmpSendEcho2的声明为:
    Private Declare Function IcmpSendEcho2 Lib "icmp.dll" _
      (ByVal IcmpHandle As Long, _
       ByVal Events As Long, _
       ByVal ApcRoutine As Long, _
       ByVal ApcContext As Long, _
       ByVal DestinationAddress As Long, _
       ByVal RequestData As String, _
       ByVal RequestSize As Integer, _
       RequestOptions As IP_OPTION_INFORMATION, _
       ReplyBuffer As ICMP_ECHO_REPLY, _
       ByVal ReplySize As Long, _
       ByVal Timeout As Long) As Long
      

  15.   

    不过看了很多例程:
    将 RequestOptions As IP_OPTION_INFORMATION换为
    ByVal RequestOptions As Long也应该没什么问题
      

  16.   

    Good!!! rainstormmaster(暴风雨 v2.0)的回答正是我想要的。不过IcmpSendEcho2这个函数在调用的时候出了一点问题,我不清楚
     ByVal ApcRoutine As Long, 
     ByVal ApcContext As Long, 
    这两个参数该传什么值。(传0会导致调用失败)
    不知道rainstormmaster(暴风雨 v2.0)能不能指点一二。多谢!
      

  17.   

    ByVal ApcRoutine As Long
    这是一个回调,应该传入一个函数的指针
      

  18.   

    我认为
    ByVal Events As Long
    这个参数才应该传入函数指针吧。而且我都尝试过了。不管哪个参数传入指针函数都是立即返回失败。
    而且不应该是其它参数的问题,因为我用同样的方法调IcmpSendEcho是成功的。
    两个函数不同的参数只有:
      ByVal Events As Long, 
       ByVal ApcRoutine As Long, 
       ByVal ApcContext As Long, 
    这三个而已。
      

  19.   

    看来是我搞错了!
    ByVal ApcRoutine As Long
    应该传入函数指针
    然而
    ByVal Events As Long

    ByVal ApcContext As Long
    这两个参数却很怪,不管我怎么设置都没有回调消息传回来。算了,结贴散分了。多谢rainstormmaster(暴风雨 v2.0)。