复制内容到剪贴板
代码:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "checksum.h"
#include <stdio.h>
#include <io.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::btnfilepathClick(TObject *Sender)
{
if(OpenFile->Execute())
{
edtfilepath->Text = OpenFile->FileName;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::btnchecksumClick(TObject *Sender)
{
if(edtfilepath->Text == "")
{
Application->MessageBoxA("请选择文件!","ERROR",48);
}
else
{
FILE *file;
int sum = 0,file_no,i = 0;
//long filesize = 0;
HANDLE FileHandle = CreateFile((edtfilepath->Text).c_str(),
GENERIC_READ, // Read only required
FILE_SHARE_READ, // read share file
NULL, // SecurityAttributes - none in Win95
OPEN_EXISTING, // how to create
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
NULL // handle of file with attributes to copy
);
if(FileHandle == INVALID_HANDLE_VALUE)
{
Application->MessageBoxA("Open File Error!","ERROR",48);
}
/*if((file = fopen((edtfilepath->Text).c_str(),"r")) == NULL)
{
Application->MessageBoxA("Open File Error!","ERROR",48);
}*/
else
{
unsigned long dwRead;
DWORD dataSize = GetFileSize(FileHandle, NULL);
unsigned char* ptrBufChk=(unsigned char*)new char[dataSize];
ReadFile (FileHandle, ptrBufChk, dataSize, &dwRead, NULL);
//file_no = fileno(file);
//filesize = filelength(file_no);
//char *buffer = (char*)new char[dataSize];
//fscanf(file,"%s",buffer);
//fread(buffer,1,filesize,file);
/*while(k<dataSize)
{
ptrBufChk[k] += 0x00000100;
k++;
}*/
unsigned int j = ptrBufChk[2];
while(i<dataSize)
{
sum = (sum + ptrBufChk)&0xFFFF;
i++;
}
unsigned long iFixLength = (dataSize<=0x800000) ? 0x800000 : 0x1000000;
for(;i<iFixLength;i++)
{
sum = (sum + 0xff)& 0xffff; // & 0xffff
}
edtchecksum->Text = (AnsiString)"0x" +(AnsiString)(IntToHex((int)(sum&0xFFFF), 4));
CloseHandle(FileHandle);
delete ptrBufChk;
}
}
}
//---------------------------------------------------------------------------