library Dog;{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }uses
  SysUtils, Windows, Messages, Forms, Dialogs,
  Classes,
  uGetMachineID in 'uGetMachineID.pas',
  uGlobal in 'uGlobal.pas',
  PTools in 'PTools.pas';
function GetMachineStr:pchar; export; //获取机器码
begin
  Result := pchar(GetIdeDiskSerialNumber +'#'+ KbGetCpuID() +'#'+ NbGetMac());
end;
function CheckDogFile(DogFileName:pchar) : Boolean; Export;  var
  DogFile : TStringList;
begin
  Result := False;
  if not FileExists(DogFileName) then
  begin
    Application.MessageBox('加密狗文件没有找到,请检查!','提示信息',MB_OK or MB_ICONERROR);
    Exit;
  end;
  DogFile := TStringList.Create;
  DogFile := ReadDogFile(DogFileName);
  if DogFile.Strings[7] = 'Y' then
  begin
    Application.MessageBox('系统License已锁定,请联系软件供应商!','提示信息',MB_OK or MB_ICONERROR);
    Exit;
  end;  //检测License控制方式
  {
   0: 不检测机器码(按使用日期控制)
   1:校对CPU信息
   2:校对硬碟信息
   3:校对网卡信息
   4:校对CPU+硬碟+网卡信息
  }
  case StrToInt(DogFile.Strings[0]) of    //检测License控制方式
    1:
      if DogFile.Strings[1] <> KbGetCpuID() then
      begin
        Application.MessageBox('系统机器码校对错误!','提示信息',MB_OK or MB_ICONERROR);
        Exit;
      end;
    2:
      if DogFile.Strings[2] <> GetIdeDiskSerialNumber then
      begin
        Application.MessageBox('系统机器码校对错误!','提示信息',MB_OK or MB_ICONERROR);
        Exit;
      end;
    3:
      if DogFile.Strings[3] <> NbGetMac() then
      begin
        Application.MessageBox('系统机器码校对错误!','提示信息',MB_OK or MB_ICONERROR);
        Exit;
      end;
    4:
      if DogFile.Strings[4] <> GetMachineStr then
      begin
        Application.MessageBox('系统机器码校对错误!','提示信息',MB_OK or MB_ICONERROR);
        Exit;
      end;
  end;  Result := WriteDogFile(DogFile,DogFileName);end;
function ReadDogFile(DogFileName:pchar) : TStringList; export;  //读文件
begin
  try
    Result := TStringList.Create;
    Result.LoadFromFile(DogFileName);
    Result := SplitString(StrDeCrypt(Result.Text),'`');  //需要解密
  except
    begin
      Application.MessageBox('读取文件失败!','提示信息',MB_OK or MB_ICONERROR);
      Exit;
    end;
  end;
end;function WriteDogFile(LicenseStr:TStringList;DogFileName:pchar) : Boolean; export;  //写文件
var
  DogFile : TStringList;
  i : Integer;
  KeyStr : String;
begin
  Result := False;
  try
    DogFile := TStringList.Create;
    for i := 0 to LicenseStr.Count -1 do
    begin
      KeyStr := KeyStr + LicenseStr.Strings[i] + '`';
    end;
    if KeyStr[Length(KeyStr)] = '`' then
      KeyStr := copy(KeyStr,1,Length(KeyStr)-1);    DogFile.Text := StrEnCrypt(KeyStr);   //需要加密
    DogFile.SaveToFile(DogFileName);
    Result := true;
  except
    begin
      Application.MessageBox('写文件失败!','提示信息',MB_OK or MB_ICONERROR);
      Result := False;
    end;
  end;
end;exports
  CheckDogFile,
  ReadDogFile,
  WriteDogFile,
  GetMachineStr;{$R *.res}beginend.