现在需要 IcmpSendEcho2 的VB声明,可是找了半天,没有找到,只搜到了VC的声明,哪位朋友有VB的声明帮忙贴一下,或者能帮忙翻译一下。谢谢了。
这是微软网站的VC声明 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/icmpsendecho2.asp
这是微软网站的VC声明 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/icmpsendecho2.asp
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)
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)
你可以参考一下.
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
这该怎么办?
这该怎么办?我不知道你是什么操作系统,我用的2000server中的icmp.dll这个dll文件没有IcmpSendEcho2这个导出函数(IcmpSendEcho函数可用),你还是找找Icmpapi.dll这个文件吧
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/icmpsendecho2.asp
系统是XP SP2 ,当声明为 icmpapi.dll 的时候是提示没有找到文件。而当声明为 icmp 的时候却提示调用约定错误。
这说明这个函数确实存在于 icmp.dll 中,只是声明的时候的参数不对。
还是请各位朋友再指点一下,尤其是 TechnoFantasy(冰儿马甲www.applevb.com) 版主,您看看是不是翻译有误?
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
将 RequestOptions As IP_OPTION_INFORMATION换为
ByVal RequestOptions As Long也应该没什么问题
ByVal ApcRoutine As Long,
ByVal ApcContext As Long,
这两个参数该传什么值。(传0会导致调用失败)
不知道rainstormmaster(暴风雨 v2.0)能不能指点一二。多谢!
这是一个回调,应该传入一个函数的指针
ByVal Events As Long
这个参数才应该传入函数指针吧。而且我都尝试过了。不管哪个参数传入指针函数都是立即返回失败。
而且不应该是其它参数的问题,因为我用同样的方法调IcmpSendEcho是成功的。
两个函数不同的参数只有:
ByVal Events As Long,
ByVal ApcRoutine As Long,
ByVal ApcContext As Long,
这三个而已。
ByVal ApcRoutine As Long
应该传入函数指针
然而
ByVal Events As Long
和
ByVal ApcContext As Long
这两个参数却很怪,不管我怎么设置都没有回调消息传回来。算了,结贴散分了。多谢rainstormmaster(暴风雨 v2.0)。