Packet Sniffer SDK DLL Edition

HNAdapter wrapper for C#

 Previous Next

File: HNAdapter.cs

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Runtime.InteropServices;
using microOLAP.PSSDK.NDIS;

namespace microOLAP.PSSDK
{
    /// <summary>
    /// Summary description for HNAdapter.
    /// </summary>
    public partial class HNAdapter : Component
    {
        #region DLL exports
        
        /// <summary>
        /// Creates an HNAdapter object. 
        /// </summary>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpCreate")]
        private static extern IntPtr AdpCreate();

        /// <summary>
        /// Destroys an HNAdapter object.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpDestroy")]
        private static extern int AdpDestroy(IntPtr hAdp);

        /// <summary>
        /// Opens the network adapter.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpOpenAdapter")]
        private static extern int AdpOpenAdapter(IntPtr hAdp);

        /// <summary>
        /// Closes the network adapter. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpCloseAdapter")]
        private static extern int AdpCloseAdapter(IntPtr hAdp);

        /// <summary>
        /// Returns network adapter open time.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetOpenTime")]
#if WIN64
        private static extern long AdpGetOpenTime(IntPtr hAdp);
#else
        private static extern uint AdpGetOpenTime(IntPtr hAdp, ref int HiValue);
#endif

        /// <summary>
        /// Shows HNAdapter working status. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpIsOpened")]
        private static extern bool AdpIsOpened(IntPtr hAdp);

        /// <summary>
        /// Returns the handle of the HNAdapterConfig object. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetConfig")]
        private static extern IntPtr AdpGetConfig(IntPtr hAdp);

        /// <summary>
        /// Sets the handle of the HNAdapterConfig object. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="hCfg"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetConfig")]
        private static extern IntPtr AdpSetConfig(IntPtr hAdp, IntPtr hCfg);

        /// <summary>
        /// Returns the MAC filter for the network adapter. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetMacFilter")]
        private static extern int AdpGetMacFilter(IntPtr hAdp);

        /// <summary>
        /// Sets the MAC filter for the network adapter. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="MacFilter"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetMacFilter")]
        private static extern int AdpSetMacFilter(IntPtr hAdp, int MacFilter);

        /// <summary>
        /// Returns the handle of the HNUserFilter object. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetUserFilter")]
        private static extern IntPtr AdpGetUserFilter(IntPtr hAdp);

        /// <summary>
        /// Sets the handle of the HNUserFilter object. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="hUserFilter"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetUserFilter")]
        private static extern IntPtr AdpSetUserFilter(IntPtr hAdp, IntPtr hUserFilter);

        /// <summary>
        /// Returns the status flag of the user-settable packet filter using. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetUserFilterActive")]
        private static extern bool AdpGetUserFilterActive(IntPtr hAdp);

        /// <summary>
        /// Sets the status flag of the user-settable packet filter using. 
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="bActiveBpf"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetUserFilterActive")]
        private static extern bool AdpSetUserFilterActive(IntPtr hAdp, bool bActiveBpf);

        /// <summary>
        /// Returns the status flag of the FastBPF using.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetUseFastUserFilter")]
        private static extern bool AdpGetUseFastUserFilter(IntPtr hAdp);

        /// <summary>
        /// Sets the status flag of the FastBPF using.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="bUseFastBpf"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetUseFastUserFilter")]
        private static extern bool AdpSetUseFastUserFilter(IntPtr hAdp, bool bUseFastBpf);

        /// <summary>
        /// Returns the network adapter maximum speed in 100 bps.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetLinkSpeed")]
        private static extern uint AdpGetLinkSpeed(IntPtr hAdp);

        /// <summary>
        /// Returns the status of the physical connection with the network.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetConnectStatus")]
        private static extern bool AdpGetConnectStatus(IntPtr hAdp);

        /// <summary>
        /// Returns the maximal number of the threads allowed to be created for work with the network adapter.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetMaxThreadCount")]
        private static extern int AdpGetMaxThreadCount(IntPtr hAdp);

        /// <summary>
        /// Returns the number of threads created for work with the network adapter.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetThreadCount")]
        private static extern int AdpGetThreadCount(IntPtr hAdp);

        /// <summary>
        /// Sets the number of threads created for work with the network adapter.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="ThreadCount"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetThreadCount")]
        private static extern int AdpSetThreadCount(IntPtr hAdp, int ThreadCount);

        /// <summary>
        /// Returns the number of the packets received by the Packet Sniffer SDK internal driver from OS.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetRecvCount")]
#if WIN64
        private static extern ulong AdpGetRecvCount(IntPtr hAdp);
#else
        private static extern uint AdpGetRecvCount(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the number of the packets passed by the user-settable packet filter.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetAcceptCount")]
#if WIN64
        private static extern ulong AdpGetAcceptCount(IntPtr hAdp);
#else
        private static extern uint AdpGetAcceptCount(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the number of packets rejected by the user-settable packet filter.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetRejectCount")]
#if WIN64
        private static extern ulong AdpGetRejectCount(IntPtr hAdp);
#else
        private static extern uint AdpGetRejectCount(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the number of the packets transferred to the application.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetProcessCount")]
#if WIN64
        private static extern ulong AdpGetProcessCount(IntPtr hAdp);
#else
        private static extern uint AdpGetProcessCount(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the number of the packets lost by the Packet Sniffer SDK internal driver.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetLostCount")]
#if WIN64
        private static extern ulong AdpGetLostCount(IntPtr hAdp);
#else
        private static extern uint AdpGetLostCount(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the number of the packets transferred by the network adapter without errors.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetTranWithoutErr")]
#if WIN64
        private static extern ulong AdpGetTranWithoutErr(IntPtr hAdp);
#else
        private static extern uint AdpGetTranWithoutErr(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the number of the packets received by the network adapter without errors.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetRecvWithoutErr")]
#if WIN64
        private static extern ulong AdpGetRecvWithoutErr(IntPtr hAdp);
#else
        private static extern uint AdpGetRecvWithoutErr(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the number of the packets transferred by the network adapter with errors.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetTranWithErr")]
#if WIN64
        private static extern ulong AdpGetTranWithErr(IntPtr hAdp);
#else
        private static extern uint AdpGetTranWithErr(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the number of the packets received by the network adapter with errors.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetRecvWithErr")]
#if WIN64
        private static extern ulong AdpGetRecvWithErr(IntPtr hAdp);
#else
        private static extern uint AdpGetRecvWithErr(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the number of the packets lost by the network adapter.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetMissed")]
#if WIN64
        private static extern ulong AdpGetMissed(IntPtr hAdp);
#else
        private static extern uint AdpGetMissed(IntPtr hAdp, ref uint HiValue);
#endif

        /// <summary>
        /// Sends a packet synchronously.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="pPacket"></param>
        /// <param name="PacketSize"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSyncSend")]
        private static extern int AdpSyncSend(IntPtr hAdp, IntPtr pPacket, uint PacketSize);

        /// <summary>
        /// Sends a packet asynchronously.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="pPacket"></param>
        /// <param name="PacketSize"></param>
        /// <param name="Count"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpAsyncSend")]
        private static extern int AdpAsyncSend(IntPtr hAdp, IntPtr pPacket, uint PacketSize, int Count, IntPtr Key);

        /// <summary>
        /// Updates the user-settable filter statistics synchronously.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpUpdateUserStatistics")]
        private static extern int AdpUpdateUserStatistics(IntPtr hAdp);

        /// <summary>
        /// Updates the network adapter statistics synchronously.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpUpdateAdapterStatistics")]
        private static extern int AdpUpdateAdapterStatistics(IntPtr hAdp);

        /// <summary>
        /// Updates network adapter statistics synchronously.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="StatisticsType"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetAsyncStatistics")]
        private static extern int AdpGetAsyncStatistics(IntPtr hAdp, int StatisticsType);

        /// <summary>
        /// Sets the OnPacketReceive event.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="pfOnPacketReceive"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetOnPacketRecv")]
        private static extern IntPtr AdpSetOnPacketRecv(IntPtr hAdp, CallBackOnPacketReceive pfOnPacketReceive, IntPtr Param);

        /// <summary>
        /// Sets the OnAsyncSend event.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="pfOnAsyncSend"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetOnAsyncSend")]
        private static extern IntPtr AdpSetOnAsyncSend(IntPtr hAdp, CallBackOnAsyncSend pfOnAsyncSend, IntPtr Param);

        /// <summary>
        /// Sets the OnStateChange event.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="pfOnStateChange"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetOnStateChange")]
        private static extern IntPtr AdpSetOnStateChange(IntPtr hAdp, CallBackOnStateChange pfOnStateChange, IntPtr Param);

        /// <summary>
        /// Sets the OnStatistics event.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="pfOnStatistics"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetOnStatistics")]
        private static extern IntPtr AdpSetOnStatistics(IntPtr hAdp, CallBackOnStatistics pfOnStatistics, IntPtr Param);

        /// <summary>
        /// Sends a packet synchronously.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="hPkt"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSyncSendEx")]
        private static extern int AdpSyncSendEx(IntPtr hAdp, IntPtr hPkt);

        /// <summary>
        /// Sends a packet asynchronously.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="hPkt"></param>
        /// <param name="Count"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpAsyncSendEx")]
        private static extern int AdpAsyncSendEx(IntPtr hAdp, IntPtr hPkt, int Count, IntPtr Key);

        /// <summary>
        /// Returns the handle of the Receive HNQueue object.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetReceiveQueue")]
        private static extern IntPtr AdpGetReceiveQueue(IntPtr hAdp);

        /// <summary>
        /// Sets the handle of the Receive HNQueue object.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="hQue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetReceiveQueue")]
        private static extern IntPtr AdpSetReceiveQueue(IntPtr hAdp, IntPtr hQue);

        /// <summary>
        /// Returns the handle of the Send HNQueue object.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetSendQueue")]
        private static extern IntPtr AdpGetSendQueue(IntPtr hAdp);

        /// <summary>
        /// Sets the handle of the Send HNQueue object.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="hQue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetSendQueue")]
        private static extern IntPtr AdpSetSendQueue(IntPtr hAdp, IntPtr hQue);

        /// <summary>
        /// Sets the OnThreadBegin event.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="pfOnThreadBegin"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetOnThreadBegin")]
        private static extern IntPtr AdpSetOnThreadBegin(IntPtr hAdp, CallBackOnThreadBegin pfOnThreadBegin, IntPtr Param);

        /// <summary>
        /// Sets the OnThreadEnd event.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="pfOnThreadEnd"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetOnThreadEnd")]
        private static extern IntPtr AdpSetOnThreadEnd(IntPtr hAdp, CallBackOnThreadEnd pfOnThreadEnd, IntPtr Param);

        /// <summary>
        /// Returns flag status of using High Precision Time.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetUseHighPrecisionTime")]
        private static extern bool AdpGetUseHighPrecisionTime(IntPtr hAdp);

        /// <summary>
        /// Sets flag status of using High Precision Time.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="bUseHighPrecision"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetUseHighPrecisionTime")]
        private static extern bool AdpSetUseHighPrecisionTime(IntPtr hAdp, bool bUseHighPrecision);

        /// <summary>
        /// Returns flag status of using Dont Loop Back.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetUseDontLoopBack")]
        private static extern bool AdpGetUseDontLoopBack(IntPtr hAdp);

        /// <summary>
        /// Sets flag status of using Dont Loop Back.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="bUseDontLoopBack"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetUseDontLoopBack")]
        private static extern bool AdpSetUseDontLoopBack(IntPtr hAdp, bool bUseDontLoopBack);

        /// <summary>
        /// Execute synchronous NDIS request.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="Oid"></param>
        /// <param name="RequestType"></param>
        /// <param name="pBuffer"></param>
        /// <param name="BufferSize"></param>
        /// <param name="pBytesUsed"></param>
        /// <param name="pBytesNeeded"></param>
        /// <param name="pNdisStatus"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSyncRequest")]
        private static extern int AdpSyncRequest(IntPtr hAdp, uint Oid, int RequestType,
           IntPtr pBuffer, uint BufferSize, ref uint pBytesUsed, ref uint pBytesNeeded, ref uint pNdisStatus);

        /// <summary>
        /// Execute asynchronous NDIS request.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="Oid"></param>
        /// <param name="RequestType"></param>
        /// <param name="pBuffer"></param>
        /// <param name="BufferSize"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpAsyncRequest")]
        private static extern int AdpAsyncRequest(IntPtr hAdp, uint Oid, int RequestType,
           IntPtr pBuffer, uint BufferSize, IntPtr Key);

        /// <summary>
        /// Sets the OnAsyncRequest event.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="pfOnAsyncRequest"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetOnAsyncRequest")]
        private static extern IntPtr AdpSetOnAsyncRequest(IntPtr hAdp, CallBackOnAsyncRequest pfOnAsyncRequest, IntPtr Param);

        /// <summary>
        /// Return the size of the packets pool which is used by PSSDK for transfering captured packets from the internal driver to application and back.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpGetPacketPool")]
        private static extern uint AdpGetPacketPool(IntPtr hAdp);

        /// <summary>
        /// Set the size of the packets pool which is used by PSSDK for transfering captured packets from the internal driver to application and back.
        /// </summary>
        /// <param name="hAdp"></param>
        /// <param name="dwPacketPool"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "AdpSetPacketPool")]
        private static extern uint AdpSetPacketPool(IntPtr hAdp, uint dwPacketPool);

        #endregion
        
        #region HNAdapter events
        
        /// <summary>
        /// CallBack OnThreadBegin.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        private delegate void CallBackOnThreadBegin(IntPtr Param, ref IntPtr ThParam);

        /// <summary>
        /// CallBack OnThreadEnd.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        private delegate void CallBackOnThreadEnd(IntPtr Param, IntPtr ThParam);

        /// <summary>
        /// CallBack OnPacketReceive.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        /// <param name="hPacket"></param>
        /// <param name="pPacketData"></param>
        /// <param name="IncPacketSize"></param>
        private delegate void CallBackOnPacketReceive(IntPtr Param, IntPtr ThParam, IntPtr hPacket, IntPtr pPacketData, uint IncPacketSize);

        /// <summary>
        /// CallBack OnAsyncSend.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="Key"></param>
        /// <param name="Count"></param>
        private delegate void CallBackOnAsyncSend(IntPtr Param, IntPtr Key, uint Count);

        /// <summary>
        /// CallBack OnStateChange.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="State"></param>
        private delegate void CallBackOnStateChange(IntPtr Param, int State);

        /// <summary>
        /// CallBack OnStatistics.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="StatisticsType"></param>
        /// <param name="pValue"></param>
        private delegate void CallBackOnStatistics(IntPtr Param, int StatisticsType, ref long pValue);

        /// <summary>
        /// CallBack OnAsyncRequest.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="Key"></param>
        /// <param name="RequestType"></param>
        /// <param name="Oid"></param>
        /// <param name="pBuffer"></param>
        /// <param name="BufferSize"></param>
        /// <param name="BytesUsed"></param>
        /// <param name="BytesNeeded"></param>
        /// <param name="NdisStatus"></param>
        private delegate void CallBackOnAsyncRequest(IntPtr Param, IntPtr Key, int RequestType, uint Oid, IntPtr pBuffer, uint BufferSize, uint BytesUsed, uint BytesNeeded, uint NdisStatus);

        /// <summary>
        /// CallBack variable OnThreadBegin.
        /// </summary>
        private CallBackOnThreadBegin pfOnThreadBegin;

        /// <summary>
        /// CallBack variable OnThreadEnd.
        /// </summary>
        private CallBackOnThreadEnd pfOnThreadEnd;

        /// <summary>
        /// CallBack variable OnPacketReceive.
        /// </summary>
        private CallBackOnPacketReceive pfOnPacketReceive;

        /// <summary>
        /// CallBack variable OnAsyncSend.
        /// </summary>
        private CallBackOnAsyncSend pfOnAsyncSend;

        /// <summary>
        /// CallBack variable OnStateChange.
        /// </summary>
        private CallBackOnStateChange pfOnStateChange;

        /// <summary>
        /// CallBack variable OnStatistics.
        /// </summary>
        private CallBackOnStatistics pfOnStatistics;

        /// <summary>
        /// CallBack variable OnAsyncRequest.
        /// </summary>
        private CallBackOnAsyncRequest pfOnAsyncRequest;

        /// <summary>
        /// OnThreadBegin event handler.
        /// </summary>
        public event OnThreadBeginEventHandler OnThreadBegin;

        /// <summary>
        /// OnThreadEnd event handler.
        /// </summary>
        public event OnThreadEndEventHandler OnThreadEnd;

        /// <summary>
        /// OnPacketReceive event handler.
        /// </summary>
        public event OnPacketReceiveEventHandler OnPacketReceive;

        /// <summary>
        /// OnAsyncSend event handler.
        /// </summary>
        public event OnAsyncSendEventHandler OnAsyncSend;

        /// <summary>
        /// OnStateChange event handler.
        /// </summary>
        public event OnStateChangeEventHandler OnStateChange;

        /// <summary>
        /// OnStatistics event handler.
        /// </summary>
        public event OnStatisticsEventHandler OnStatistics;

        /// <summary>
        /// OnAsyncRequest event handler.
        /// </summary>
        public event OnAsyncRequestEventHandler OnAsyncRequest;

        #endregion

        /// <summary>
        /// Handle of the HNAdapter object.
        /// </summary>
        private IntPtr hAdp = IntPtr.Zero;
        
        /// <summary>
        /// Adapter config.
        /// </summary>
        private HNAdapterConfig configHandle = null;
        
        /// <summary>
        /// User (bpf) filter.
        /// </summary>
        private HNUserFilter userFilter = null;
        
        /// <summary>
        /// Receive packet queue.
        /// </summary>
        private HNQueue receiveQueue = null;

        /// <summary>
        /// Send packet queue.
        /// </summary>
        private HNQueue sendQueue = null;
        
        /// <summary>
        /// Constructor of the HNAdapter object.
        /// </summary>
        public HNAdapter()
        {
            InitializeComponent();

            hAdp = AdpCreate();
            if (hAdp != IntPtr.Zero)
            {
                pfOnThreadBegin = new CallBackOnThreadBegin(this.DoOnThreadBegin);
                AdpSetOnThreadBegin(hAdp, pfOnThreadBegin, IntPtr.Zero);

                pfOnThreadEnd = new CallBackOnThreadEnd(this.DoOnThreadEnd);
                AdpSetOnThreadEnd(hAdp, pfOnThreadEnd, IntPtr.Zero);

                pfOnPacketReceive = new CallBackOnPacketReceive(this.DoOnPacketReceive);
                AdpSetOnPacketRecv(hAdp, pfOnPacketReceive, IntPtr.Zero);

                pfOnAsyncSend = new CallBackOnAsyncSend(this.DoOnAsyncSend);
                AdpSetOnAsyncSend(hAdp, pfOnAsyncSend, IntPtr.Zero);

                pfOnStateChange = new CallBackOnStateChange(this.DoOnStateChange);
                AdpSetOnStateChange(hAdp, pfOnStateChange, IntPtr.Zero);

                pfOnStatistics = new CallBackOnStatistics(this.DoOnStatistics);
                AdpSetOnStatistics(hAdp, pfOnStatistics, IntPtr.Zero);

                pfOnAsyncRequest = new CallBackOnAsyncRequest(this.DoOnAsyncRequest);
                AdpSetOnAsyncRequest(hAdp, pfOnAsyncRequest, IntPtr.Zero);
            }
        }

        /// <summary>
        /// Destroys an HNAdapter object.
        /// </summary>
        ~HNAdapter()
        {
            if (hAdp != IntPtr.Zero) AdpDestroy(hAdp);
        }

        #region HNAdapter properties
        
        /// <summary>
        /// Checks if the HNAdapter object is created correctly.
        /// </summary>
        [Browsable(false)]
        public bool IsValid
        {
            get
            {
                return (hAdp != IntPtr.Zero);
            }
        }

        /// <summary>
        /// Sets/Returns the handle of the Receive HNQueue object.
        /// </summary>
        public HNQueue ReceiveQueue
        {
            get
            {
                if (AdpGetReceiveQueue(hAdp) != IntPtr.Zero)
                {
                    return receiveQueue;
                }
                else
                {
                    receiveQueue = null;
                    return receiveQueue;
                }
            }
            set
            {
                if (value != null)
                {
                    receiveQueue = value;
                    AdpSetReceiveQueue(hAdp, receiveQueue.Handle);
                }
                else
                {
                    AdpSetReceiveQueue(hAdp, IntPtr.Zero);
                }
            }
        }

        /// <summary>
        /// Sets/Returns the handle of the Send HNQueue object.
        /// </summary>
        public HNQueue SendQueue
        {
            get
            {
                if (AdpGetSendQueue(hAdp) != IntPtr.Zero)
                {
                    return sendQueue;
                }
                else
                {
                    sendQueue = null;
                    return sendQueue;
                }
            }
            set
            {
                if (value != null)
                {
                    sendQueue = value;
                    AdpSetSendQueue(hAdp, sendQueue.Handle);
                }
                else
                {
                    AdpSetSendQueue(hAdp, IntPtr.Zero);
                }
            }
        }

        /// <summary>
        /// Sets/Returns the handle of the HNAdapterConfig object.
        /// </summary>
        [Browsable(false)]
        public HNAdapterConfig ConfigHandle
        {
            get
            {
                if (AdpGetConfig(hAdp) != IntPtr.Zero)
                {
                    return configHandle;
                }
                else
                {
                    configHandle = null;
                    return configHandle;
                }
            }
            set
            {
                if (value != null)
                {
                    configHandle = value;
                    AdpSetConfig(hAdp, configHandle.Handle);
                }
                else
                {
                    AdpSetConfig(hAdp, IntPtr.Zero);
                }
            }
        }

        /// <summary>
        /// Sets/returns the MAC filter for the network adapter.
        /// </summary>
        public HNMacFilter MacFilter
        {
            get
            {
                return (HNMacFilter)AdpGetMacFilter(hAdp);
            }
            set
            {
                AdpSetMacFilter(hAdp, (int)value);
            }
        }

        /// <summary>
        /// Sets/Returns the handle of the HNUserFilter object.
        /// </summary>
        [Browsable(false)]
        public HNUserFilter UserFilter
        {
            get
            {
                if (AdpGetUserFilter(hAdp) != IntPtr.Zero)
                {
                    return userFilter;
                }
                else
                {
                    userFilter = null;
                    return userFilter;
                }
            }
            set
            {
                if (value != null)
                {
                    userFilter = value;
                    AdpSetUserFilter(hAdp, userFilter.Handle);
                }
                else
                {
                    AdpSetUserFilter(hAdp, IntPtr.Zero);
                }
            }
        }

        /// <summary>
        /// Sets/Returns the status flag of the user-settable packet filter using.
        /// </summary>
        public bool UserFilterActive
        {
            get
            {
                return AdpGetUserFilterActive(hAdp);
            }
            set
            {
                AdpSetUserFilterActive(hAdp, value);
            }
        }

        /// <summary>
        /// Sets/Returns the status flag of the FastBPF using.
        /// </summary>
        public bool UseFastUserFilter
        {
            get
            {
                return AdpGetUseFastUserFilter(hAdp);
            }
            set
            {
                AdpSetUseFastUserFilter(hAdp, value);
            }
        }

        /// <summary>
        /// Sets/Returns the status flag of the High Precision Time using.
        /// </summary>
        public bool UseHighPrecisionTime
        {
            get
            {
                return AdpGetUseHighPrecisionTime(hAdp);
            }
            set
            {
                AdpSetUseHighPrecisionTime(hAdp, value);
            }
        }

        /// <summary>
        /// Sets/Returns the status flag of using Dont Loop Back.
        /// </summary>
        public bool UseDontLoopBack
        {
            get
            {
                return AdpGetUseDontLoopBack(hAdp);
            }
            set
            {
                AdpSetUseDontLoopBack(hAdp, value);
            }
        }

        /// <summary>
        /// Returns the network adapter maximum speed in 100 bps.
        /// </summary>
        [Browsable(false)]
        public uint LinkSpeed
        {
            get
            {
                return AdpGetLinkSpeed(hAdp);
            }
        }

        /// <summary>
        /// Returns the status of the physical connection to the network.
        /// </summary>
        [Browsable(false)]
        public bool ConnectStatus
        {
            get
            {
                return AdpGetConnectStatus(hAdp);
            }
        }

        /// <summary>
        /// Returns the maximal number of the threads allowed to be created for work with the network adapter.
        /// </summary>
        public int MaxThreadCount
        {
            get
            {
                return AdpGetMaxThreadCount(hAdp);
            }
        }

        /// <summary>
        /// Sets/Returns the number of threads created for work with the network adapter.
        /// </summary>
        public int ThreadCount
        {
            get
            {
                return AdpGetThreadCount(hAdp);
            }
            set
            {
                AdpSetThreadCount(hAdp, value);
            }
        }

        /// <summary>
        /// Shows HNAdapter working status.
        /// </summary>
        [Browsable(false)]
        public bool IsOpened
        {
            get
            {
                return AdpIsOpened(hAdp);
            }
        }

        /// <summary>
        /// Returns the time of the latest opening of the current network adapter.
        /// </summary>
        [Browsable(false)]
        public long OpenTime
        {
            get
            {
#if WIN64
                return AdpGetOpenTime(hAdp);
#else
                uint LowValue = 0; int HighValue = 0;
                LowValue = AdpGetOpenTime(hAdp, ref HighValue);
                return ((((long)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets received by the Packet Sniffer SDK internal driver from OS.
        /// </summary>
        [Browsable(false)]
        public uint RecvCount32
        {
            get
            {
#if WIN64
                return (uint)AdpGetRecvCount(hAdp);
#else
                uint HighValue = 0;
                return AdpGetRecvCount(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets received by the Packet Sniffer SDK internal driver from OS.
        /// </summary>
        [Browsable(false)]
        public ulong RecvCount64
        {
            get
            {
#if WIN64
                return AdpGetRecvCount(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetRecvCount(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets passed by the user-settable packet filter.
        /// </summary>
        [Browsable(false)]
        public uint AcceptCount32
        {
            get
            {
#if WIN64
                return (uint)AdpGetAcceptCount(hAdp);
#else
                uint HighValue = 0;
                return AdpGetAcceptCount(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets passed by the user-settable packet filter.
        /// </summary>
        [Browsable(false)]
        public ulong AcceptCount64
        {
            get
            {
#if WIN64
                return AdpGetAcceptCount(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetAcceptCount(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of packets rejected by the user-settable packet filter.
        /// </summary>
        [Browsable(false)]
        public uint RejectCount32
        {
            get
            {
#if WIN64
                return (uint)AdpGetRejectCount(hAdp);
#else
                uint HighValue = 0;
                return AdpGetRejectCount(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of packets rejected by the user-settable packet filter.
        /// </summary>
        [Browsable(false)]
        public ulong RejectCount64
        {
            get
            {
#if WIN64
                return AdpGetRejectCount(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetRejectCount(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets transferred to the application.
        /// </summary>
        [Browsable(false)]
        public uint ProcessCount32
        {
            get
            {
#if WIN64
                return (uint)AdpGetProcessCount(hAdp);
#else
                uint HighValue = 0;
                return AdpGetProcessCount(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets transferred to the application.
        /// </summary>
        [Browsable(false)]
        public ulong ProcessCount64
        {
            get
            {
#if WIN64
                return AdpGetProcessCount(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetProcessCount(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets lost by the Packet Sniffer SDK internal driver.
        /// </summary>
        [Browsable(false)]
        public uint LostCount32
        {
            get
            {
#if WIN64
                return (uint)AdpGetLostCount(hAdp);
#else
                uint HighValue = 0;
                return AdpGetLostCount(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets lost by the Packet Sniffer SDK internal driver.
        /// </summary>
        [Browsable(false)]
        public ulong LostCount64
        {
            get
            {
#if WIN64
                return AdpGetLostCount(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetLostCount(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets transferred by the network adapter without errors.
        /// </summary>
        [Browsable(false)]
        public uint TranWithoutErr32
        {
            get
            {
#if WIN64
                return (uint)AdpGetTranWithoutErr(hAdp);
#else
                uint HighValue = 0;
                return AdpGetTranWithoutErr(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets transferred by the network adapter without errors.
        /// </summary>
        [Browsable(false)]
        public ulong TranWithoutErr64
        {
            get
            {
#if WIN64
                return AdpGetTranWithoutErr(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetTranWithoutErr(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets received by the network adapter without errors.
        /// </summary>
        [Browsable(false)]
        public uint RecvWithoutErr32
        {
            get
            {
#if WIN64
                return (uint)AdpGetRecvWithoutErr(hAdp);
#else
                uint HighValue = 0;
                return AdpGetRecvWithoutErr(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets received by the network adapter without errors.
        /// </summary>
        [Browsable(false)]
        public ulong RecvWithoutErr64
        {
            get
            {
#if WIN64
                return AdpGetRecvWithoutErr(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetRecvWithoutErr(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets transferred by the network adapter with errors.
        /// </summary>
        [Browsable(false)]
        public uint TranWithErr32
        {
            get
            {
#if WIN64
                return (uint)AdpGetTranWithErr(hAdp);
#else
                uint HighValue = 0;
                return AdpGetTranWithErr(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets transferred by the network adapter with errors.
        /// </summary>
        [Browsable(false)]
        public ulong TranWithErr64
        {
            get
            {
#if WIN64
                return AdpGetTranWithErr(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetTranWithErr(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets received by the network adapter with errors.
        /// </summary>
        [Browsable(false)]
        public uint RecvWithErr32
        {
            get
            {
#if WIN64
                return (uint)AdpGetRecvWithErr(hAdp);
#else
                uint HighValue = 0;
                return AdpGetRecvWithErr(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets received by the network adapter with errors.
        /// </summary>
        [Browsable(false)]
        public ulong RecvWithErr64
        {
            get
            {
#if WIN64
                return AdpGetRecvWithErr(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetRecvWithErr(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets lost by the network adapter.
        /// </summary>
        [Browsable(false)]
        public uint Missed32
        {
            get
            {
#if WIN64
                return (uint)AdpGetMissed(hAdp);
#else
                uint HighValue = 0;
                return AdpGetMissed(hAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets lost by the network adapter.
        /// </summary>
        [Browsable(false)]
        public ulong Missed64
        {
            get
            {
#if WIN64
                return AdpGetMissed(hAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = AdpGetMissed(hAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Sets/returns the size of the packets pool which is used by PSSDK for transfering captured packets from the internal driver to application and back.
        /// </summary>
        public uint PacketPool
        {
            get
            {
                return AdpGetPacketPool(hAdp);
            }
            set 
            {
                AdpSetPacketPool(hAdp, value);
            }
        }

        #endregion
        
        #region HNAdapter methods
        
        /// <summary>
        /// Opens the network adapter.
        /// </summary>
        /// <returns></returns>
        public PSSDKRES OpenAdapter()
        {
            return (PSSDKRES)AdpOpenAdapter(hAdp);
        }

        /// <summary>
        /// Closes the network adapter.
        /// </summary>
        /// <returns></returns>
        public PSSDKRES CloseAdapter()
        {
            return (PSSDKRES)AdpCloseAdapter(hAdp);
        }

        /// <summary>
        /// Sends a packet synchronously.
        /// </summary>
        /// <param name="pPacket"></param>
        /// <param name="PacketSize"></param>
        /// <returns></returns>
        public PSSDKRES SyncSend(IntPtr pPacket, uint PacketSize)
        {
            return (PSSDKRES)AdpSyncSend(hAdp, pPacket, PacketSize);
        }

        /// <summary>
        /// Sends a packet asynchronously.
        /// </summary>
        /// <param name="pPacket"></param>
        /// <param name="PacketSize"></param>
        /// <param name="Count"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public PSSDKRES AsyncSend(IntPtr pPacket, uint PacketSize, int Count, IntPtr Key)
        {
            return (PSSDKRES)AdpAsyncSend(hAdp, pPacket, PacketSize, Count, Key);
        }

        /// <summary>
        /// Updates the user-settable filter statistics synchronously.
        /// </summary>
        /// <returns></returns>
        public PSSDKRES UpdateUserStatistics()
        {
            return (PSSDKRES)AdpUpdateUserStatistics(hAdp);
        }

        /// <summary>
        /// Updates the network adapter statistics synchronously.
        /// </summary>
        /// <returns></returns>
        public PSSDKRES UpdateAdapterStatistics()
        {
            return (PSSDKRES)AdpUpdateAdapterStatistics(hAdp);
        }


        /// <summary>
        /// Updates network adapter statistics synchronously.
        /// </summary>
        /// <param name="StatisticsType"></param>
        /// <returns></returns>
        public PSSDKRES GetAsyncStatistics(HNStatisticsType statisticsType)
        {
            return (PSSDKRES)AdpGetAsyncStatistics(hAdp, (int)statisticsType);
        }

        /// <summary>
        /// Execute synchronous NDIS request.
        /// </summary>
        /// <param name="Oid"></param>
        /// <param name="RequestType"></param>
        /// <param name="pBuffer"></param>
        /// <param name="BufferSize"></param>
        /// <param name="pBytesUsed"></param>
        /// <param name="pBytesNeeded"></param>
        /// <param name="pNdisStatus"></param>
        /// <returns></returns>
        public PSSDKRES SyncRequest(uint Oid, int RequestType, IntPtr pBuffer, uint BufferSize,
           ref uint pBytesUsed, ref uint pBytesNeeded, ref uint pNdisStatus)
        {
            return (PSSDKRES)AdpSyncRequest(hAdp, Oid, RequestType, pBuffer, BufferSize, ref pBytesUsed, ref pBytesNeeded, ref pNdisStatus);
        }

        /// <summary>
        /// Execute asynchronous NDIS request.
        /// </summary>
        /// <param name="Oid"></param>
        /// <param name="RequestType"></param>
        /// <param name="pBuffer"></param>
        /// <param name="BufferSize"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public PSSDKRES AsyncRequest(uint Oid, int RequestType, IntPtr pBuffer, uint BufferSize, IntPtr Key)
        {
            return (PSSDKRES)AdpAsyncRequest(hAdp, Oid, RequestType, pBuffer, BufferSize, Key);
        }

        #endregion

        #region HNAdapter callBacks

        /// <summary>
        /// Tracks the creating of the internal component thread.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        private void DoOnThreadBegin(IntPtr Param, ref IntPtr ThParam)
        {
            if (OnThreadBegin != null)
                OnThreadBegin(this, ref ThParam);
        }

        /// <summary>
        /// Tracks the closing of the internal component thread.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        private void DoOnThreadEnd(IntPtr Param, IntPtr ThParam)
        {
            if (OnThreadEnd != null)
                OnThreadEnd(this, ThParam);
        }

        /// <summary>
        /// Occurs immediately after a packet has been received by the network adapter.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        /// <param name="hPacket"></param>
        /// <param name="pPacketData"></param>
        /// <param name="IncPacketSize"></param>
        private void DoOnPacketReceive(IntPtr Param, IntPtr ThParam, IntPtr hPacket, IntPtr pPacketData, uint IncPacketSize)
        {
            if (OnPacketReceive != null)
                OnPacketReceive(this, ThParam, hPacket, pPacketData, IncPacketSize);
        }

        /// <summary>
        /// Occurs immediately after the asynchronous packet sending has been completed.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="Key"></param>
        /// <param name="Count"></param>
        private void DoOnAsyncSend(IntPtr Param, IntPtr Key, uint Count)
        {
            if (OnAsyncSend != null)
                OnAsyncSend(this, Key, Count);
        }

        /// <summary>
        /// Occurs when the network adapter state has been changed.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="State"></param>
        private void DoOnStateChange(IntPtr Param, int State)
        {
            if (OnStateChange != null)
                OnStateChange(this, (HNNetAdapterStateChange)State);
        }

        /// <summary>
        /// Occurs when network adapter statistics has been updated asynchronously.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="StatisticsType"></param>
        /// <param name="pValue"></param>
        private void DoOnStatistics(IntPtr Param, int StatisticsType, ref long pValue)
        {
            if (OnStatistics != null)
                OnStatistics(this, (HNStatisticsType)StatisticsType, ref pValue);
        }

        /// <summary>
        /// Fires immediately after asynchronous NDIS request completed.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="Key"></param>
        /// <param name="RequestType"></param>
        /// <param name="Oid"></param>
        /// <param name="pBuffer"></param>
        /// <param name="BufferSize"></param>
        /// <param name="BytesUsed"></param>
        /// <param name="BytesNeeded"></param>
        /// <param name="NdisStatus"></param>
        private void DoOnAsyncRequest(IntPtr Param, IntPtr Key, int RequestType, uint Oid, IntPtr pBuffer, uint BufferSize, uint BytesUsed, uint BytesNeeded, uint NdisStatus)
        {
            if (OnAsyncRequest != null)
                OnAsyncRequest(this, Key, (NDIS_REQUEST_TYPE)RequestType, Oid, pBuffer, BufferSize, BytesUsed, BytesNeeded, (NDIS_STATUS)NdisStatus);
        }

        #endregion
    }
}
See also:HNAdapter, All wrappers in one ZIP archive