Simple packaged file operation class [original]

xiaoxiao2021-03-06  21

/ / =========================================================================================================================================================================================== ========= //// Copyright (C) 2000-2004 iWise Technologies, Co. Ltd.///////product: IW988 // file: myfile.h // created : Tianda Sewed //// Description: // ValueAdded Main Program for IW988.// Contact: // Waterpub@mail.9cbs.net/ / / ============== ===================================================

#pragma overce

Class CMYFILE

{

PUBLIC:

CMYFILE ();

Virtual ~ CMYFILE

Void);

Bool Open (LPCTSTR LPSZFILENAME, UINT NOPENFLAGS);

// open a file

Uint Read (

Void * lpbuf, uint ncount);

// read the file

DWORD WRITE

Const

Void * lpbuf, uint ncount);

// write file

Handle getsafehandle ()

{

IF (! m_hfile)

Return NULL;

Return M_HFILE;

}

Virtual __int64 getLength ()

CONST;

// File size

Intclose ();

// Turn the file

Char * getFilename ();

// file name

Private:

Handle M_HFILE;

// file handle

CHAR * M_PFILENAME;

// Full file name

PUBLIC:

ENUM OPENMODE

{

ModeRead

=

1,

Modewrite

=

2

}

}

/ / =========================================================================================================================================================================================== ========= //// Copyright (C) 2000-2004 iWise Technologies, Co. Ltd.///////product: IW988 // file: myfile.cpp // created : Tianda Sewed //// Description: // ValueAdded Main Program for IW988.// Contact: // Waterpub@mail.9cbs.net/ / / ============== ============================================ # include

"Stdafx.h"

#include

"myfile.h"

#include

CMYFILE :: CMYFILE (): m_hfile (null), M_PFileName (NULL)

{

}

CMYFILE :: ~ CMYFILE

Void)

{

CLOSE ();

}

Bool CMYFILE :: Open (lpctstr lpszfilename, uint nopenflags)

{

CLOSE ();

DWORD DWDESIREDACCESS;

DWORD DWCREATIONDISPSITION;

Switch (Nopenflags)

{

Case ModeRead:

DwdesiredAccess

= Generic_read;

DWCREATIONDisPosition

= OPEN_EXISTING;

Break;

Case Modewrite:

DwdesiredAccess

= Generic_write;

DWCREATIONDisPosition

= OPEN_ALWAYS;

Break;

DEFAULT:

Assert (false);

}

Handle Hfile

= CREATEFILE (LPSZFILENAME, DWDESIREDACCESS,

0,

// Do not share

NULL, DWCREATIONDISPSION,

File_attribute_normal, null;

IF (HFile

! = INVALID_HANDLE_VALUE)

{

m_hfile

= HFILE;

M_PFileName

=

New

Char [Strlen (LPSZFileName)

1];

STRCPY (M_PFileName, LPSZFileName);

Return True;}

Else

{

Hfile

= NULL;

Return False;

}

}

INT CMYFILE :: Close ()

{

IF (m_hfile)

{

CloseHandle (M_HFILE);

m_hfile

= NULL;

}

IF (m_pfilename)

{

delete [] m_pfilename;

M_PFileName

= NULL;

}

Return

0;

}

Uint CMYFILE :: Read (

Void * LPBUF, UINT NCOUNT)

{

askERT (M_HFILE);

IF (m_hfile)

{

DWORD NNUMBEROFBYTESREAD;

IF (ReadFile (M_HFile, LPBUF, NCOUNT, & NNUMBEROFBYTESREAD, NULL)

{

Return (uint) nnumberofbytesread;

}

}

Return

0;

}

DWORD CMYFILE :: Write

Const

Void * LPBUF, UINT NCOUNT)

{

askERT (M_HFILE);

DWORD DWRECEIVE

=

0;

/ / The number of bytes actually written

IF (m_hfile)

{

Writefile (M_HFile, LPBUF, NCOUNT, & DWRECEIVE, NULL);

}

Return dwreceive;

}

__INT64 CMYFILE :: getLength ()

Const

{

IF (! m_hfile)

Return

0;

Ularge_integer Lisize

=

{

0,

0

}

Lisize.lowpart

= :: getFileSize (m_hfile, & lisize.highpart);

Return (__INT64) Lisize.quadpart;

}

Char * cmyfile :: getFilename ()

{

Return M_PFileName;

}

转载请注明原文地址:https://www.9cbs.com/read-79387.html

New Post(0)