Packet Sniffer SDK DLL Edition

HNPSManager wrapper for Delphi

 Previous Next

File: HNPSManager.pas

{****************************************************************************
**                                                                         **
**                        PSSDK HNPSManager module                         **
**            Copyright (c) 1997 - 2007 microOLAP Technologies LTD,        **
**                       Khalturin A.P., Naumov D.A.                       **
**                                                                         **
****************************************************************************}

unit HNPSManager;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  HNPsSdkDef;

type
  TOnConfigChange = procedure(Sender : TObject; hConfig : Pointer; ChangeType : Integer) of object;

  //---------------------------------------------------------------------------
  // Class THNPSManager
  //---------------------------------------------------------------------------
  THNPSManager = class
   private
     hMgr   : Pointer;
     FOnConfigChange: TOnConfigChange;
     function GetVersion: AnsiString;
     function GetBuild: AnsiString;
     procedure SetWanMonitorState(Value: BOOL);
     function GetWanMonitorState: BOOL;
     function GetAdaptersCfgCount: DWORD;
     procedure DoOnConfigChange(hConfig: Pointer; ChangeType: DWORD);
     // Add in v3.1
     function GetIsInitialized: BOOL;
     function GetIsProtocolInstalled: BOOL;
     function GetIsLoopBackInstalled: BOOL;

   protected
   public
     constructor Create();
     destructor  Destroy(); override;
     function IsValid: BOOL;
     function Initialize: DWORD;
     procedure About();
     function Get_FirstAdapterCfg: Pointer;
     function Get_NextAdapterCfg(hPrevCfg: Pointer): Pointer;
     function RefreshAdapterList: DWORD;
     property Version: AnsiString read GetVersion;
     property Build: AnsiString read GetBuild;
     property AdaptersCfgCount: DWORD read GetAdaptersCfgCount;
     // Add in v3.1
     property IsInitialized: BOOL read GetIsInitialized;
     property IsProtocolInstalled: BOOL read GetIsProtocolInstalled;
     function InstallProtocol(UniqueInstallID : String) : DWORD;
     function UninstallProtocol(UniqueInstallID : String) : DWORD;
     property IsLoopBackInstalled: BOOL read GetIsLoopBackInstalled;
     function InstallLoopBack(UniqueInstallID : String) : DWORD;
     function UninstallLoopBack(UniqueInstallID : String) : DWORD;
     function UnloadProtocolNtDriver() : DWORD;

   published
     property WanMonitorState: BOOL read GetWanMonitorState write SetWanMonitorState;
     property OnConfigChange: TOnConfigChange read FOnConfigChange write FOnConfigChange;

  end;

implementation

{$INCLUDE 'HNPsSdkFun.pas'}

//---------------------------------------------------------------------------
// IntOnConfigChange - OnConfigChange event handler.
//---------------------------------------------------------------------------
procedure IntOnConfigChange(Param : Pointer; hConfig : Pointer ; ChangeType : Integer); stdcall;
 var
   pMgr : THNPSManager;
 begin
   pMgr := THNPSManager(Param);
   pMgr.DoOnConfigChange(hConfig,ChangeType);
 end;

//---------------------------------------------------------------------------
// Create - Creates an HNPSManager object.
//---------------------------------------------------------------------------
constructor THNPSManager.Create();
 begin
   hMgr := MgrCreate();
   MgrSetOnConfigChange(hMgr,@IntOnConfigChange,Self);
 end;

//---------------------------------------------------------------------------
// Destroy - Destroys an HNPSManager object.
//---------------------------------------------------------------------------
destructor THNPSManager.Destroy();
 begin
   MgrSetOnConfigChange(hMgr,nil,nil);
   MgrDestroy(hMgr);
 end;

//---------------------------------------------------------------------------
// Method - IsValid - Checks if the HNPSManager object has been created correctly.
//---------------------------------------------------------------------------
function THNPSManager.IsValid: BOOL;
 begin
   Result := BOOL(hMgr <> nil);
 end;

//---------------------------------------------------------------------------
// Method - About - Displays information about Packet Sniffer SDK.
//---------------------------------------------------------------------------
procedure THNPSManager.About();
 begin
   MgrAbout(hMgr);
 end;

//---------------------------------------------------------------------------
// Property - Version - Returns the version number of the Packet Sniffer SDK library.
//---------------------------------------------------------------------------
function THNPSManager.GetVersion: AnsiString;
 begin
   Result := MgrGetVersion(hMgr);
 end;

//---------------------------------------------------------------------------
// Property - Build - Returns the build number of the Packet Sniffer SDK library.
//---------------------------------------------------------------------------
function THNPSManager.GetBuild: AnsiString;
 begin
   Result := MgrGetBuild(hMgr);
 end;

//---------------------------------------------------------------------------
// Property - WanMonitorState - Sets the WANMonitor installation status.
//---------------------------------------------------------------------------
procedure THNPSManager.SetWanMonitorState(Value: BOOL);
 begin
    MgrSetWanMonitorState(hMgr,Value);
 end;

//---------------------------------------------------------------------------
// Property - WanMonitorState - Returns the WANMonitor installation status.
//---------------------------------------------------------------------------
function THNPSManager.GetWanMonitorState: BOOL;
 begin
   Result := MgrGetWanMonitorState(hMgr);
 end;

//---------------------------------------------------------------------------
// Method - Initialize - Initializes Packet Sniffer SDK.
//---------------------------------------------------------------------------
function THNPSManager.Initialize: DWORD;
 begin
   Result := MgrInitialize(hMgr);
 end;

//---------------------------------------------------------------------------
// Property - AdaptersCfgCount - Returns the number of the HNAdapterConfig objects.
//---------------------------------------------------------------------------
function THNPSManager.GetAdaptersCfgCount: DWORD;
 begin
   Result := MgrGetAdaptersCfgCount(hMgr);
 end;

//---------------------------------------------------------------------------
// Method - Get_FirstAdapter - Returns the handle of the first HNAdapterConfig object.
//---------------------------------------------------------------------------
function THNPSManager.Get_FirstAdapterCfg: Pointer;
 begin
   Result := MgrGetFirstAdapterCfg(hMgr);
 end;

//---------------------------------------------------------------------------
// Method - Get_NextAdapterCfg - Returns the handle of the next HNAdapterConfig object.
//---------------------------------------------------------------------------
function THNPSManager.Get_NextAdapterCfg(hPrevCfg: Pointer): Pointer;
 begin
   Result := MgrGetNextAdapterCfg(hMgr,hPrevCfg);
 end;

//---------------------------------------------------------------------------
// Method - RefreshAdapterList - Refreshes the internal list of the HNAdapterConfig objects.
//---------------------------------------------------------------------------
function THNPSManager.RefreshAdapterList: DWORD;
 begin
   Result := MgrRefreshAdapterList(hMgr);
 end;

//---------------------------------------------------------------------------
// DoOnConfigChange - Fires when the network adapter configuration changes.
//---------------------------------------------------------------------------
procedure THNPSManager.DoOnConfigChange(hConfig: Pointer; ChangeType: DWORD);
 begin
   if Assigned(FOnConfigChange) then FOnConfigChange(Self,hConfig,ChangeType);
 end;

 //---------------------------------------------------------------------------
// v3.1 - MgrIsInitialized - Return PSSDK initialization status
//---------------------------------------------------------------------------
function THNPSManager.GetIsInitialized() : BOOL;
 begin
   Result := MgrIsInitialized(hMgr);
 end;

//---------------------------------------------------------------------------
// v3.1 - MgrIsProtocolInstalled - Return status of installation the protocol driver of the current PSSDK version
//---------------------------------------------------------------------------
function THNPSManager.GetIsProtocolInstalled() : BOOL;
 begin
   Result := MgrIsProtocolInstalled();
 end;

//---------------------------------------------------------------------------
// v3.1 - MgrIsLoopBackInstalled - Return status of the loopback driver installation for current version of PSSDK
//---------------------------------------------------------------------------
function THNPSManager.GetIsLoopBackInstalled() : BOOL;
 begin
   Result := MgrIsLoopBackInstalled();
 end;

//---------------------------------------------------------------------------
// v3.1 - MgrInstallProtocolA - Install protocol driver for current PSSDK version
//---------------------------------------------------------------------------
function THNPSManager.InstallProtocol(UniqueInstallID : String) : DWORD;
 begin
   Result := MgrInstallProtocol(PChar(UniqueInstallID));
 end;

//---------------------------------------------------------------------------
// v3.1 - MgrUninstallProtocolA - Uninstall protocol driver for current PSSDK version
//---------------------------------------------------------------------------
function THNPSManager.UninstallProtocol(UniqueInstallID : String) : DWORD;
 begin
   Result := MgrUninstallProtocol(PChar(UniqueInstallID));
 end;

//---------------------------------------------------------------------------
// v3.1 - MgrUnloadProtocolNtDriver - unload protocol driver for current version of PSSDK (windows nt/2k/xp/2k3/vista)
//---------------------------------------------------------------------------
function THNPSManager.UnloadProtocolNtDriver() : DWORD;
 begin
   Result := MgrUnloadProtocolNtDriver();
 end;

//---------------------------------------------------------------------------
// v3.1 - MgrInstallLoopBackA - Install loopback driver for current version of PSSDK
//---------------------------------------------------------------------------
function THNPSManager.InstallLoopBack(UniqueInstallID : String) : DWORD;
 begin
   Result := MgrInstallLoopBack(PChar(UniqueInstallID));
 end;

//---------------------------------------------------------------------------
// v3.1 - MgrUninstallLoopBackA - Uninstall loopback driver for current version of PSSDK
//---------------------------------------------------------------------------
function THNPSManager.UninstallLoopBack(UniqueInstallID : String) : DWORD;
 begin
   Result := MgrUninstallLoopBack(PChar(UniqueInstallID));
 end;

end.
See also:HNPSManager, All wrappers in one ZIP archive