How to Use

As the first step you always have to create at least one instance of PacketX . To work with multiple network adapters create one instance of PacketX for each network interface.
There is also an ActiveX control version of PacketX available. The PacketXCtrl introduces a little bit more overhead to your application by adding another layer of code. PacketXCtrl properties are persistable and can be modified using custom property pages .
Warning:
If move your application or development project using PacketXCtrl between two computers you have to reset the adapters collection.
The following sections help you to get started with Microsoft Visual Basic, Visual C++, VBScript, Internet Explorer, Borland C++ Builder and Delfi.

Visual Basic:

To use the PacketX in your project you have to add reference to the type library . This can be done using the Visual Basic References dialog from Project menu:
HowToVB1.gif

Figure 1. Importing the PacketX type library

To use the PacketXCtrl control in your application you need to add the control to Visual Basic Components Palette. This can be done using the Components dialog from Project menu:
HowToVB2.gif

Figure 2. Importing the PacketX control

After that new icon labeled PKT will appear on the components palette in the Visual Basic IDE. Below is a screen shot taken after successful component installation:
HowToVB3.gif

Figure 3. PacketX on the Components Palette

Visual C++:

There are two possible ways to use PacketX from Visual C++ application: use smart pointer classes generated by compiler or using the PacketXCtrl class placed on some window or dialog box.
Win32 command line applications cannot use ActiveX controls. In this case you have the option to import the type library and use smart pointer classes generated by the compiler. Put the following line into your stdafx.h file:
 #import "PacketX.dll" no_namespace, named_guids 
The import statement will force compiler to generate wrapper classes for ActiveX objects found in type library. Now you should be able to compile the following piece of code:
 // Initialize COM
 CoInitialize(NULL);

 // Create PacketX 
 IPktXPacketXPtr pPktX;
 pPktX.CreateInstance(__uuidof(PacketX)); 
Let's see how to use the PacketXCtrl control from Visual C++. For that purpose we create a new MFC application. To create a new MFC dialog based application, choose New option from File menu and take the following steps:
HowToVC1.gif

Step 1. Choose MFC AppWizard (.exe)

HowToVC2.gif

Step 2. Choose application type (dialog)

HowToVC3.gif

Step 3. Enable support for ActiveX controls

Now you have created an empty dialog based MFC application. At this point you can compile and run it. As the next step we are going to add the ActiveX control to empty dialog resource. Open the dialog resource in Visual C++ IDE and use the right mouse button to popup context menu. Select the Insert ActiveX Control... item from popup menu to display the following dialog:
HowToVC4.gif

Step 4. Insert ActiveX control

Next you need to generate C++ wrapper class for the control. Open the ClassWizard and go to Member Variables tab. Select CPktXDlg from the class list. Select IDC_PACKETXCTRL1 from control id’s list and click Add Variable button. After you have completed these steps you should see new CPkXPacketXCtrl item in class view:
HowToVC5.gif

Step 5. Add C++ wrapper class

As the final step create event handlers for the control OnPacket and OnStatistics events. This can be done using the ClassWizard or just by double clicking on the PacketXCtrl item in the dialog resource.
HowToVC6.gif

Step 6. Add event handlers

VBscript:

Because you need to handle events in VBScript you have to use the WScript.CreateObject function to create the PacketX instance. The CreateObject function accepts the class prog id as the first parameter and prefix to event handler function as second parameter:
 '// Create PackeX instance
 Set oPktX = WScript.CreateObject("PktX.PacketX","PacketX_")
 ...
 Public Sub PacketX_OnPacket(ByRef oPacket)
   '// Process packet ...
 End Sub 
To construct prog id for a class take the class name and add the "PktX." prefix to it. For example to the prog id for the Adapter class would be "PktX.Adapter".

C++ Builder and Delfi:

Borland development environments interface to PacketX through the ActiveX API. There are some differences from Visual Basic in setting up the Borland IDE to use PacketX. These differences are easily accounted for, but their existence is not always obvious.
To use PacketX classes with a Borland Delphi or C++ Builder, you must first import the type library. This will install the PacketXCtrl control and other classes into the ActiveX palette of the Borland IDE. To import the type library, click on the Import Type Library selection from the Project menu:
HowToDelphi1.gif

Figure 1. Importing the PacketX type library

At this point Delphi or C++ Builder will generate a package for the PacketX type library. New ActiveX control and class icons will appear on the ActiveX tab in the Borland IDE. This process can take several seconds. Each time Delphi or C++ Builder is invoked, PacketX control and class icons will appear on the ActiveX tab:
HowToDelphi2.gif

Figure 2. PacketX on the Component Palette

To remove the PacketX control from the IDE, click on the Install Packages selection from the Components menu. From the list of packages, select User Components or Borland User Components. Click on the Components button to view/verify the selected package contains the PacketX control. Click OK to dismiss the window displaying the controls associated with a selected package. Click the Remove button to remove the package and controls from the Borland IDE.

Internet Explorer:

To use PacketXCtrl from Internet Explorer add the following piece of code to your HTML document:
 <object id=pktx style="display:none" classid="clsid:0276C5E0-FDDD-470D-957C-5A3E2438D7F5"
   codebase="http://www.beesync.com/files/PacketX.dll" viewastext>
 </object>

 <script language="vbscript" for="pktx" event="onpacket(byref opacket)">
 <!-- 'Add your code here ... 
 --></script>
 
 <script language="vbscript" for="pktx" event="onstatistics(byref ostats)">
 <!-- 'Add your code here ...
 --></script>

capture decode statistics

Filter:


Copyright © 2000-2007 beeSync. All rights reserved.