Hello, I am doing an audio recording application. I am writing the audio data to a file. I am trying to read the data in the file and add it to a buffer. During debugging, I find the error is pointing to:
ASSERT(AfxIsValidAddress(lpBuf, nCount));
of the
CFile::Read
function. Here is the code:
void CWaveIn::WriteWaveFile()
{
CString* databuf;
databuf = NULL;
databuf = new CString;
CFile my_file,f1;
if(my_file.Open(m_strFile,CFile::modeRead|CFile::shareDenyNone,NULL))
{
unsigned int x = ;
int iRead = my_file.Read((void*)databuf, my_file.GetLength());
.....
If you think, I have problem with my recording, I am pasting that code as well:
(I am using a callback thread, for recording. The thread's function is written below)
DWORD WINAPI CWaveIn::ThreadProc(LPVOID lpParameter)
{
CWaveIn* pWaveIn = (CWaveIn*)lpParameter;
MSG msg;
DWORD dwWait = 0;
DWORD dwUser = 0;
WAVEHDR *pWaveHdr = NULL;
if (pWaveIn == NULL)
{
return -1;
}
while ((dwWait = WaitForSingleObject(pWaveIn->m_hEventKill, 5)) != 0)
{
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
switch (msg.message)
{
case MM_WIM_DATA:
EnterCriticalSection(&pWaveIn->m_critSecRtp);
pWaveHdr = (WAVEHDR*)msg.lParam;
if (pWaveHdr)
{
waveInUnprepareHeader(pWaveIn->m_hWaveIn, pWaveHdr, sizeof(WAVEHDR));
dwUser = pWaveHdr->dwUser;
fwrite(pWaveHdr->lpData, 1, pWaveHdr->dwBytesRecorded, pWaveIn->m_fRecord);
ZeroMemory(pWaveHdr, sizeof(WAVEHDR));
pWaveHdr->dwBufferLength = BYTES_PER_HDR;
pWaveHdr->lpData = (char*)pWaveIn->m_HdrBuffer[dwUser];
pWaveHdr->dwUser = dwUser;
waveInPrepareHeader(pWaveIn->m_hWaveIn, pWaveHdr, sizeof(WAVEHDR));
waveInAddBuffer(pWaveIn->m_hWaveIn, pWaveHdr, sizeof(WAVEHDR));
}
LeaveCriticalSection(&pWaveIn->m_critSecRtp);
break;
default:
break;
}
}
}
CloseHandle(pWaveIn->m_thread);
pWaveIn->m_thread = NULL;
return 0;
}