当前位置:编程学习 > VB >>

求VC++,vb以及易语言的各种源代码

凡是有关的都要,要源代码,不要编译后的!打包给我发来吧,什么样的都行,编译器自带的就算了
补充:shaomingshuai@126.com
答案:既然你没有要求的话,我就给你一个C++的测网速的代码

#include "stdafx.h"
#include <stdio.h>
#include <windows.h> 
#include <wininet.h>


#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "wininet.lib")


typedef DWORD  (__stdcall *IcmpSendEcho)(HANDLE,IPAddr,LPVOID,WORD,PIP_OPTION_INFORMATION,LPVOID,DWORD,DWORD);
typedef HANDLE (__stdcall *IcmpCreateFile)(void);
typedef BOOL   (__stdcall *IcmpCloseHandle)(HANDLE);


 IcmpCreateFile  fIcmpCreateFile;
 IcmpSendEcho    fIcmpSendEcho;
 IcmpCloseHandle fIcmpCloseHandle;



BOOL InitFun(void)
{
HMODULE lModl;
lModl=(HMODULE)LoadLibrary ("Iphlpapi.dll");
if (lModl==0) {
printf("Load the library has error!\n");
return FALSE;
}
    else{
    fIcmpCreateFile=(IcmpCreateFile)GetProcAddress (lModl,"IcmpCreateFile");
   fIcmpSendEcho=(IcmpSendEcho)GetProcAddress (lModl,"IcmpSendEcho");
    fIcmpCloseHandle=(IcmpCloseHandle)GetProcAddress (lModl,"IcmpCloseHandle");
        if (fIcmpCreateFile==NULL || fIcmpSendEcho==NULL || fIcmpCloseHandle==NULL){
   printf("Load the function has error!\n");
   return FALSE;
}
   return TRUE;
}
}
LPHANDLE GetPingHandle(void)
{
HANDLE pHandle;
    pHandle=fIcmpCreateFile();
if ((int)pHandle==-1){
printf("Load ICMP handle has error!\n");
return 0;
}
else{
return (LPHANDLE)pHandle;
}
}
BOOL Ping(LPSTR pIPAddr)
{
HANDLE iHwnd;
iHwnd=(HANDLE)GetPingHandle();
IPAddr pAddr;
pAddr=(IPAddr)inet_addr ((char *)pIPAddr);
icmp_echo_reply pData;
for(int i=1;i<=LoopSend;i++)
{
        fIcmpSendEcho(iHwnd,pAddr,NULL,0,NULL,(LPVOID)&pData,sizeof(icmp_echo_reply),0);
if (pData.Status==0)
{
       printf("Ping测试返回的结果: Time=%dms TTL=%d \n",(int)pData.RoundTripTime,(int)pData.Options.Ttl);
}
else
{
printf("Ping测试失败...\n");
}


}
    if (!fIcmpCloseHandle(iHwnd)) printf("Close handle has Error!\n");
return TRUE;
}


至于main函数的话你可以自己写,只要传入一个IP地址给Ping函数就可以运行了


与它对应的VB模块代码

Private Declare Function IcmpCreateFile Lib "iphlpapi.dll" () As Long
Private Declare Function IcmpSendEcho Lib "iphlpapi.dll" (ByVal IcmpHandle As Long, ByVal DestinationAddress As Long, ByVal RequestData As String, ByVal RequestSize As Long, ByVal RequestOptions As Long, ReplyBuffer As ICMP_ECHO_REPLY, ByVal ReplySize As Long, ByVal Timeout As Long) As Long
Private Declare Function IcmpCloseHandle Lib "iphlpapi.dll" (ByVal IcmpHandle As Long) As Long
Private Declare Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Long


Private Type IP_OPTION_INFORMATION
   ttl     As Byte                    '    ‘生存时间
   Tos    As Byte                   '     ‘服务类型
   Flags As Byte                    '    ‘IP头标志
   OptionsSize      As Byte         ' ‘选项数据的大小,字节
   OptionsData     As Long        ' ‘指向选项数据的指针
End Type


Private Type ICMP_ECHO_REPLY
   Address  As Long                  ''‘包含正回复的IP地址
   Status  As Long          '          ‘包含回复的状态(参看后面的常量部分)
   RoundTripTime  As Long     ' ‘往返时间RTT(毫秒)
   DataSize  As Integer          '   ‘回复数据大小(字节)
   Reserved  As Integer           '  ‘保留
   ptrData  As Long               '   ‘指向回复数据的指针
   Options  As IP_OPTION_INFORMATION '‘回复选项
   Data  As String * 250
End Type


Public Type Rtn_ICMPTestMessage
Address As String
State As String     '''用函数写
testSuccess As Boolean '''  是否成功测试
time As Long
size As Long
ttl As Long
End Type


Public Function RtnICMPTestMessage(ByVal TestIP As String, ByVal Timeout As Long, ByVal PackSize As Long) As Rtn_ICMPTestMessage
Dim IcmpHandle As Long
IcmpHandle = IcmpCreateFile    '''创建测试句柄
Dim ICMPReply As ICMP_ECHO_REPLY
Dim LongIPAdde As Long
LongIPAddr = inet_addr(TestIP)


Dim SendData As String    '''''  为了包大小而设置
SendData = Space(PackSize)
IcmpSendEcho IcmpHandle, LongIPAddr, SendData, Len(SendData), 0, ICMPReply, Len(ICMPReply), Timeout
If ICMPReply.Status = 0 Then
RtnICMPTestMessage.Address = TestIP
RtnICMPTestMessage.size = ICMPReply.DataSize
RtnICMPTestMessage.State = RtnICMPState(ICMPReply.Status)
RtnICMPTestMessage.time = ICMPReply.RoundTripTime
RtnICMPTestMessage.ttl = ICMPReply.Options.ttl
RtnICMPTestMessage.testSuccess = True  '''测试成功


Else
RtnICMPTestMessage.Address = TestIP
RtnICMPTestMessage.State = RtnICMPState(ICMPReply.Status)
RtnICMPTestMessage.testSuccess = False  '''测试失败
End If


IcmpCloseHandle IcmpHandle
End Function

上一个:VB问题 VBVB 利用Array函数给数组a赋值
下一个:vb高手进啊 这个程序中都有哪些语句

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,