The information in this article applies to:
SUMMARYPingCtrl.exe is a sample source for an ActiveX control that demonstrates how to access complicated Winsock features from Visual Basic. PingCtrl.exe implements "ping-like" functionality so that you can test whether a particular workstation is running from a Visual Basic application. While a programmer can infer whether a workstation is running by calling some of the Lanman or WNet APIs, this is not a very flexible solution. In this case, Ping is a better solution. However, the steps involved in importing a large number of Winsock API calls required by Ping is daunting. PingCtrl.exe simplifies this process. MORE INFORMATIONThe following file is available for download from the Microsoft
Download Center. Click the file name below to download the file: PingCtrl.exeFor more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. PingCtrl.exe demonstrates how to access complicated Winsock features from Visual Basic using an ActiveX control. The control was built in Visual C++ using the ActiveX project template. Most of the files generated by the template remain unchanged. The only changes are that the properties, methods, and events were added, which was easily accomplished through the Class Wizard. From there, a class named Winsock2 was added to encapsulate all Winsock calls, including the implementation of Ping itself. See the Source Files section for a discussion of each source file and its purpose. Installation and Use
Source FilesThe following files are files associated with PingCtrl.exe:Ping.mak: The Visual C++ project makefile for building the Ping ActiveX Control. Ping.h: This is the main include file for the Ping ActiveX Control DLL. It includes other project-specific includes such as resource.h. Ping.cpp: This is the main source file that contains code for DLL initialization, termination and other bookkeeping. Ping.rc: This is a listing of the Microsoft Windows resources that the project uses. You can directly edit this file with the Visual C++ resource editor. Ping.def: This file contains information about the Ping ActiveX Control DLL that must be provided to run with Microsoft Windows. Ping.odl: This file contains the Object Description Language source code for the type library of your control. Ping.ico: This is the icon file for the application. PingCtl.h: This file contains the declaration of the CPingCtrl C++ class. This includes the definition of all control properties, events, and methods. PingCtl.cpp: This file contains the implementation of the CPingCtrl C++ class. PingPpg.h: This file contains the declaration of the CPingPropPage C++ class. PingPpg.cpp: This file contains the implementation of the CPingPropPage C++ class. PingCtl.bmp: This file contains a bitmap that a container uses to represent the CPingCtrl control when it appears on a tool palette. This bitmap is included by the main resource file Ping.rc. stdafx.h and stdafx.cpp: These files are used to build a precompiled header (PCH) file named stdafx.pch and a precompiled types (PCT) file named stdafx.obj. resource.h: This is the standard header file, which defines new resource IDs. The Visual C++ resource editor reads and updates this file. WSAErrors.h: This file contains textual strings for Winsock errors. The Win32 API FormatMessage() does not work with Winsock errors. Winsock2.h: This file contains the Winsock2 class definition that contains the code to perform an ICMP request (Ping). Winsock2.cpp: This file contains the Winsock2 class implementation. Properties, Methods, and EventsThe Ping control has the following properties: NumPackets: Sets the number of ICMP packets to send to the remote host. Timeout: Specifies the timeout value (in milliseconds) for each ICMP packet. RemoteHost: Specifies the remote computer to ping. AverageTime: Read-only. Average response time for an ICMP packet sent to a host. MaxTime: Read-only. Maximum response time for an ICMP packet sent to a host. MinTime: Read-only. Minimum response time for an ICMP packet sent to a host. The Ping control has the following methods: Ping: Initiates a ping request. This call will block for a maximum of NumPackets * Timeout seconds in order to wait for ICMP request completion. The Ping control has the following events: OnError: This event is called when a Winsock error occurs in the Ping process. OnEchoReply: This event is called when an ICMP response packet is read. The response time (in milliseconds) for this packets is returned as a parameter. OnEchoTimeout: This event gets called when no ICMP response is received in the timeout period. Sample
NotesTo implement Ping from a Winsock 2 application, you need to use raw sockets (that is, calling WSASocket with SOCK_RAW and IPPROTO_ICMP). Because of security concerns under Windows NT, only members of the Administrators group may create raw sockets. This also means that only members of the Administrators group may use the Ping control. If the error text "The requested address is a broadcast address, but the appropriate flag was not set" or error number 10013 is returned they indicate that the user does not have the proper credentials to create the raw socket. Windows 95 (with the Winsock 2 update) and Windows 98 do not have this limitation because they do not address the user security issue.Additional query words: ping
Keywords : kbnetwork kbAPI kbNTOS400 kbSDKPlatform kbWinOS95 kbWinsock kbGrpNet |
Last Reviewed: November 24, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |