Archived

This topic is now archived and is closed to further replies.

Access Violations in wdmaud.drv

This topic is 5671 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve written a class that loads a wave file into memory, takes the necessary information from it to fill a WAVEFORMATEX structure and when a function is called, a waveOut device is opened and the file is played. The file plays fine, however, when the file is finished playing, I get an access violation. The code for playing the file is below:
  
bool CWaveFile::PlayWave()
{
	HWAVEOUT hWaveOut;
	WAVEHDR  whdr;

	if (!this->data) {
		return false;
	}

	if (waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfex, 0, 0, CALLBACK_NULL) != MMSYSERR_NOERROR) {
		return false;
	}

	VirtualLock(this->data, this->dwDataSize);

	memset(&whdr, 0, sizeof(WAVEHDR));
	whdr.lpData = this->data;
	whdr.dwBufferLength = this->dwDataSize;
	whdr.dwFlags = 0;
	whdr.dwLoops = 1;
	whdr.dwBytesRecorded = 0;
	whdr.dwUser = 0;

	if (waveOutPrepareHeader(hWaveOut, &whdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
		VirtualUnlock(this->data, this->dwDataSize);
		waveOutClose(hWaveOut);
		return false;
	}

	whdr.dwFlags |= WHDR_BEGINLOOP | WHDR_ENDLOOP;

	if (waveOutWrite(hWaveOut, &whdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
		VirtualUnlock(this->data, this->dwDataSize);
		waveOutClose(hWaveOut);
		return false;
	}

	return true;
}
  
I''ve tried everything. The code above has the callback function taken out to see if it was that, which it wasn''t. The access violation isn''t caused by the buffer being too small, and there are no problems that I can see in the WAVEFORMATEX structure or WAVEHDR structure. Any ideas? Your help will be greatly appreciated.

Share this post


Link to post
Share on other sites
Note: I''m running XP, but that shouldn''t be the problem.

I''ve tried the same (well, simplified) code in VB aswell now and get the result. There is enough data in the buffer, but still the error occurs...

Share this post


Link to post
Share on other sites
I''ve got the answer now. It occurred to me this morning whilst watching TV, that I was deleting the WAVEHDR structure before waveOutWrite had finished using it. I hadn''t defined the WAVEHDR as part of the class, and it was being declared inside the function and so when the function returned (which happened before the wave had finished playing), the WAVEHDR structure was destroyed and so wdmaud.drv caused an access violation.

Ahh, sweet relief.

Share this post


Link to post
Share on other sites