xiaobin(veic_2005#163.com)

http://www.cnblogs.com/xiaobin-hlj80/

辛亥百年纪念 - 产品组件系列05

“天下为公”

    ---------------------------

    《COM组件》

                此组件目的:可供VB调用的COM。

                此组件用途:读/写FCN文件


==Code=========

FCN.dpr

(*--------------------------------------------------------------------------
   Delphi菜鸟XiaoBin  2006.5.31于黑龙江草甸子

http://blog.csdn.net/xiaobin_hlj80

veic_2005@163.com
--------------------------------------------------------------------------*)

library FCN;

uses
  Udefine in 'Udefine.pas',
  UCRC32 in 'UCRC32.pas';

{$R *.res}


EXPORTS
  saveFCNFile name 'saveFCN',
  readFCNFile name 'readFCN',
  calculateCRC32Number name 'calCRC32';

begin
end.
 

UCRC32.pas

(*--------------------------------------------------------------------------
   Delphi菜鸟XiaoBin  2006.5.31于黑龙江草甸子

http://blog.csdn.net/xiaobin_hlj80

veic_2005@163.com
--------------------------------------------------------------------------*)


unit UCRC32;

interface

uses
  Windows, SysUtils, Classes, Udefine;


type
  CRC32array=array[0..255]of Longint;

var
  crc32table:CRC32array;

procedure generateCRC32Array;
function calculateCRC32Number(filePath1:PChar):DWORD;stdcall;
procedure saveFCNFile(saveFile1,CheckFilePath:pchar);stdcall;
function readFCNFile(loadFile1:PChar):DWORD;stdcall;


implementation

procedure generateCRC32Array;
var
  i11,j22,crc:longword;
begin
  for i11:=0 to 256 do
  begin
    crc:=i11;

    for j22:=0 to 8 do
    begin
      if (crc and 1)=1 then
      begin
        crc:=(crc shr 1)xor $EDB88320;
      end
      else
      begin
        crc:=crc shr 1;
      end;
    end;
    crc32table[i11]:=crc;
  end;

end;

function calculateCRC32Number(filePath1:PChar):DWORD;
var
  crc32:DWORD;
  len:longword;
  i1:integer;
  fs:TFileStream;
  Buffer: array[1..8192] of Byte;
begin
  generateCRC32Array;
  try
    fs:=TFileStream.Create(filePath1,fmOpenRead);
    len:=fs.Read(Buffer,sizeof(Buffer));
    crc32:=$ffffffff;
    for i1:=1 to len do
    begin
      crc32:=((crc32 shr 8)and $ffffff)xor crc32table[(crc32 xor dword(Buffer[i1]))and $ff];
    end;
  finally
    fs.Free;
  end;
  Result:=crc32;
end;

procedure saveFCNFile(saveFile1,CheckFilePath:Pchar);
var
  fileStream1:TFileStream;
begin
  DeleteFile(saveFile1);
  If Not FileExists(saveFile1) Then
  Begin
    try
      fileStream1:= TFileStream.Create(saveFile1, fmCreate);
      FileHead.Version := '1.9.8.0';
      FileHead.author:='xiaobin';
      FileHead.CRC32:=calculateCRC32Number(CheckFilePath);
      Filehead.UpdateDate := Now;
      fileStream1.Write(FileHead, SizeOf(FileHead));
    finally
      fileStream1.Free;
    end;
  End;
end;

function readFCNFile(loadFile1:PChar):DWORD;stdcall;
var
  fileStream2:TFileStream;
begin
  try
    fileStream2:=TFileStream.Create(loadFile1,fmOpenRead);
    fileStream2.Read(FileHead,sizeof(FileHead));
    Result:=FileHead.CRC32;
  finally
    fileStream2.Free;
  end;
end;

end.





阅读更多
版权声明:本文为xiaobin原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaobin_HLJ80/article/details/6883868
个人分类: Delphi
想对作者说点什么? 我来说一句

iebook 模板

2009年02月09日 1.75MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭