AudioFile.cpp
资源名称:111.rar [点击查看]
上传用户:mony888
上传日期:2022-07-26
资源大小:1247k
文件大小:2k
源码类别:
Windows CE
开发平台:
Visual C++
- #include "stdafx.h"
- //#include "AudioFile.h"
- AudioFile::AudioFile()
- {
- m_pFileHdr = NULL;
- }
- AudioFile::~AudioFile()
- {
- }
- BOOL AudioFile::ToClos()
- {
- return CloseHandle(m_fh);
- }
- MMRESULT AudioFile::ToOpen(LPCTSTR lpFileName, PVOID pFilehdr, DWORD cbHdrSiz, OpenMod Flags)
- {
- DWORD cbBytsDone;
- if (READ == Flags)
- {
- m_fh = CreateFile(lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
- if (INVALID_HANDLE_VALUE == m_fh)
- {
- return MMSYSERR_ERROR;
- }
- if (!ReadFile(m_fh, pFilehdr, cbHdrSiz, &cbBytsDone, NULL) || cbBytsDone < cbHdrSiz)
- {
- return MMSYSERR_ERROR;
- }
- return MMSYSERR_NOERROR;
- }
- else if (WRIT == Flags)
- {
- m_fh = CreateFile(lpFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (INVALID_HANDLE_VALUE == m_fh)
- {
- return MMSYSERR_ERROR;
- }
- if (!WriteFile(m_fh, pFilehdr, cbHdrSiz, &cbBytsDone, NULL) || cbBytsDone < cbHdrSiz)
- {
- return MMSYSERR_ERROR;
- }
- return MMSYSERR_NOERROR;
- }
- else
- {
- return MMSYSERR_INVALPARAM;
- }
- }
- MMRESULT AudioFile::ToRead(PBYTE pBuf, DWORD cbSiz2Read, PDWORD pcbSizRead)
- {
- if (!ReadFile(m_fh, pBuf, cbSiz2Read, pcbSizRead, NULL))
- {
- return MMSYSERR_ERROR;
- }
- return MMSYSERR_NOERROR;
- }
- MMRESULT AudioFile::ToWrit(PBYTE pData, DWORD cbSiz2Writ, PDWORD pcbSizWrot)
- {
- if (!WriteFile(m_fh, pData, cbSiz2Writ, pcbSizWrot, NULL) || *pcbSizWrot < cbSiz2Writ)
- {
- return MMSYSERR_ERROR;
- }
- return MMSYSERR_NOERROR;
- }