unit mainfrm;

interface

uses
  Windows, Messages, SysUtils,{ Variants,} Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    ButtonInstDriver: TButton;
    ButtonCancel: TButton;
    LabelResult: TLabel;
    ButtonUninstallDriver: TButton;
    ButtonGetDogDriverInfo: TButton;
    ButtonDisplayInterface: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure ButtonInstDriverClick(Sender: TObject);
    procedure ButtonCancelClick(Sender: TObject);
    procedure ButtonGetDogDriverInfoClick(Sender: TObject);
    procedure ButtonDisplayInterfaceClick(Sender: TObject);
    procedure ButtonUninstallDriverClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

var dwStatus: longint;
{Declare the interface function}
  Function InstDriver(iFlag : Integer): LongWord; StdCall; external 'RCMicroDogSetup.dll'
  Function UninstallDriver(iFlag:Integer):LongWord;StdCall; external 'RCMicroDogSetup.dll'
  Function GetDogDriverInfo():Integer;StdCall; external 'RCMicroDogSetup.dll'
  procedure DriverDialog();StdCall; external 'RCMicroDogSetup.dll'
  procedure NotifyPullOutAndPlugInUsbDog(iFlag : Integer); StdCall; external 'RCMicroDogSetup.dll'
  
{$R *.dfm}

procedure TForm1.ButtonInstDriverClick(Sender: TObject);
var
   szMessage: AnsiString;
begin
  szMessage := 'Install driver,Please wait......';
  LabelResult.SetTextBuf ( PCHAR(szMessage) );
  ButtonCancel.Enabled := False ;
  ButtonDisplayInterface.Enabled := false;
  ButtonGetDogDriverInfo.Enabled := false;
  ButtonInstDriver.Enabled := false;
  ButtonUninstallDriver.Enabled :=false;

  //If you want to  display the information "If you have plugged in the USB Hardware,
  //please pull out it and plug in it again!" in Windows 98/ME,you should use 1,else
  //use 0 or don't call NotifyPullOutAndPlugInUsbDog

  NotifyPullOutAndPlugInUsbDog(1);

  dwStatus := InstDriver(3);{1 install USB dog driver 2 install Parallel dog driver 3 install both USB dog driver and Parallel dog driver}

   if (dwStatus<>0) then {0 means susccess}
      if (dwStatus = 3008) then
      begin
         szMessage := 'Please log on with administrator identity.';
           ButtonInstDriver.Enabled :=true;
          ButtonCancel.Enabled := True;
          ButtonDisplayInterface.Enabled := true;
          ButtonGetDogDriverInfo.Enabled := true;
          ButtonInstDriver.Enabled := true;
     end
     else if (dwStatus <> 3008) then
        begin
          szMessage := 'Dog Driver install failed.'+#13;
          szMessage := szMessage + 'error code = '+IntToStr(dwStatus);
          ButtonInstDriver.Enabled :=true;
          ButtonCancel.Enabled := True;
          ButtonDisplayInterface.Enabled := true;
          ButtonGetDogDriverInfo.Enabled := true;
          ButtonInstDriver.Enabled := true;

      end
      else
   else if(dwStatus = 0)   then
     begin
     szMessage := 'Dog Driver install succeeded.';
     ButtonInstDriver.Enabled :=false;
     ButtonCancel.Enabled := True;
     ButtonDisplayInterface.Enabled := true;
     ButtonGetDogDriverInfo.Enabled := true;
     ButtonUninstallDriver.Enabled := true;
    end
    else
    szMessage := 'This is invalid return code!';
       LabelResult.SetTextBuf ( PCHAR(szMessage) );
end;

procedure TForm1.ButtonCancelClick(Sender: TObject);
begin
  Close();
end;

procedure TForm1.ButtonGetDogDriverInfoClick(Sender: TObject);
var
   szMessage: AnsiString;
begin
  dwStatus := GetDogDriverInfo();
  if (dwStatus = 0) then {0 means susccess}
     begin
          szMessage := 'Not Find Dog Driver.';
     end
  else if (dwStatus = 1) then {0 means susccess}
     begin
          szMessage := 'Find the same version USBDog and ParallelDog driver.';
     end
  else if (dwStatus = 2) then {0 means susccess}
     begin
          szMessage := 'Find the same version USBDog driver only.';
     end
  else if (dwStatus = 3) then {0 means susccess}
     begin
          szMessage := 'Find the same version ParallelDog driver only.';
     end
  else if (dwStatus = 4) then {0 means susccess}
     begin
          szMessage := 'Find the older version USBDog and ParallelDog driver.';
     end
  else if (dwStatus = 5) then {0 means susccess}
     begin
          szMessage := 'Find the older version USBDog driver only.';
     end
  else if (dwStatus = 6) then {0 means susccess}
     begin
          szMessage := 'Find the older version ParallelDog driver only.';
     end
  else if (dwStatus = 7) then {0 means susccess}
     begin
          szMessage := 'Find the newer version USBDog and ParallelDog driver.';
     end
  else if (dwStatus = 8) then {0 means susccess}
     begin
          szMessage := 'Find the newer version USBDog driver only.';
     end
  else if (dwStatus = 9) then {0 means susccess}
     begin
          szMessage := 'Find the newer version ParallelDog driver only.';
     end
  else if (dwStatus = 3008) then {0 means susccess}
     begin
          szMessage := 'Please log on with administrator identify!';
     end
   else
     szMessage := 'This is an invalid return code!';
   LabelResult.SetTextBuf ( PCHAR(szMessage) );
end;

procedure TForm1.ButtonDisplayInterfaceClick(Sender: TObject);
begin
   DriverDialog();
end;

procedure TForm1.ButtonUninstallDriverClick(Sender: TObject);
var
   szMessage: AnsiString;
begin
  szMessage := 'Uninstall driver,Please wait......';
  LabelResult.SetTextBuf ( PCHAR(szMessage) );
  ButtonCancel.Enabled := False ;
  ButtonDisplayInterface.Enabled := false;
  ButtonGetDogDriverInfo.Enabled := false;
  ButtonInstDriver.Enabled := false;
  ButtonUninstallDriver.Enabled :=false;


  dwStatus := UninstallDriver(3);{1: uninstall USB dog driver 2: uninstall Parallel dog driver 3 uninstall: both USB dog driver and Parallel dog driver}

   if (dwStatus<>0) then {0 means susccess}

        if (dwStatus = 3008) then
        begin
         szMessage := 'Please log on with administrator identity.' ;
          ButtonInstDriver.Enabled :=true;
          ButtonCancel.Enabled := True;
          ButtonDisplayInterface.Enabled := true;
          ButtonGetDogDriverInfo.Enabled := true;
          ButtonInstDriver.Enabled := true;
        end
        else if (dwStatus <> 3008) then
          begin
            szMessage := 'Dog Driver uninstall failed.'+#13;
            szMessage := szMessage + 'error code = '+IntToStr(dwStatus);
            ButtonCancel.Enabled := TRUE ;
            ButtonDisplayInterface.Enabled := TRUE;
            ButtonGetDogDriverInfo.Enabled := TRUE;
            ButtonInstDriver.Enabled := TRUE;
            ButtonUninstallDriver.Enabled :=TRUE;
        end
        else


   else if (dwStatus = 0)  then
   begin
     ButtonCancel.Enabled := TRUE ;
     ButtonDisplayInterface.Enabled := TRUE;
     ButtonGetDogDriverInfo.Enabled := TRUE;
     ButtonInstDriver.Enabled := TRUE;
     ButtonUninstallDriver.Enabled :=false;
        szMessage := 'Dog Driver uninstall succeeded.';
     end
   else
     szMessage := 'This is invalid return code!';
     LabelResult.SetTextBuf ( PCHAR(szMessage) );
end;

end.
