#include "stdafx.h" /* ----------------------------------------------------------------------------- Class: MsdFile Desc: See header. Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. Chris Danford ----------------------------------------------------------------------------- */ #include "MsdFile.h" MsdFile::MsdFile() { m_szFileString = NULL; int m_iNumValues = 0; } MsdFile::~MsdFile() { if( m_szFileString ) delete m_szFileString; } //returns true if successful, false otherwise bool MsdFile::ReadFile( CString sNewPath ) { if( m_szFileString ) delete m_szFileString; // Get file size in bytes HANDLE hFile = CreateFile( sNewPath, // pointer to name of the file GENERIC_READ, // access (read-write) mode FILE_SHARE_READ|FILE_SHARE_WRITE, // share mode NULL, // pointer to security attributes OPEN_EXISTING, // how to create FILE_ATTRIBUTE_NORMAL, // file attributes NULL // handle to file with attributes to ); int iBufferSize = GetFileSize( hFile, NULL ) + 1; CloseHandle( hFile ); // allocate a string to hold the file m_szFileString = new char[iBufferSize]; FILE* fp = fopen(sNewPath, "r"); if( fp == NULL ) return false; int iBytesRead = fread( m_szFileString, 1, iBufferSize, fp ); ASSERT( iBufferSize > iBytesRead ); m_iNumValues = 0; for( int i=0; i