I'm trying to create a simple loobback between the microphone, then send it to the soundcard. I was successfully able to get data from the soundcard, but once I do waveOutWrite, I get error code 33, and I don't know what that means. I searched all over the winmm.h file, and I don't see anywhere error 33. What am I doing wrong?

Here's code:

Code:
#include <windows.h> 
#include <mmsystem.h>
#include <stdio.h>

#pragma comment (lib, "winmm.lib")

HWAVEIN WaveInHandle;
HWAVEOUT WaveOutHandle;

WAVEHDR WaveHeader; 

WAVEFORMATEX WaveFormat;

int err;

void CALLBACK waveOutProc(HWAVEOUT WaveOutHandle, UINT uMsg, DWORD dwInstance, DWORD
						  dwParam1, DWORD dwParam2)
{
	if(uMsg == WOM_DONE)
	{
		printf("Successfully written sound!!\n");
	}

	if(uMsg == WOM_OPEN)
	{
		printf("WaveOut Opened....\n");
	}

	if(uMsg == WOM_CLOSE)
	{
		printf("WaveOut closed!!\n");
	}
}

void CALLBACK waveInProc(HWAVEIN WaveInHandle, UINT uMsg, DWORD dwInstance, DWORD
dwParam1, DWORD dwParam2) 
{ 
	if (uMsg == WIM_DATA) 
	{ 
		printf("Got some data\n");
		if ((waveInAddBuffer(WaveInHandle, &WaveHeader, sizeof(WaveHeader)))) 
		{
			printf("Error while adding the buffer again...\n");
		}
		
		// error 33....
		err = waveOutWrite(WaveOutHandle,&WaveHeader,sizeof(WaveHeader));
		
			if(err != MMSYSERR_NOERROR)
			{
				printf("Error playing back data!\n");
			}
		
	}
	
	if (uMsg == WIM_OPEN)
	{
		printf("Device opened...\n");
	}

	if (uMsg == WIM_CLOSE) 
	{
		printf("Device closed...\n");
	}
}


int main()
{

int intBufferSize = 44100;

WaveFormat.nSamplesPerSec = 22050; 
WaveFormat.nChannels = 1;
WaveFormat.wBitsPerSample = 16; 
WaveFormat.wFormatTag = WAVE_FORMAT_PCM;
WaveFormat.nBlockAlign = WaveFormat.nChannels * (WaveFormat.wBitsPerSample/8);
WaveFormat.nAvgBytesPerSec = WaveFormat.nSamplesPerSec * WaveFormat.nBlockAlign;
WaveFormat.cbSize = 0;

WaveHeader.dwBufferLength = intBufferSize; 
WaveHeader.lpData = (char *)VirtualAlloc(0, intBufferSize, MEM_COMMIT, PAGE_READWRITE);
WaveHeader.dwFlags = 0; 
WaveHeader.dwLoops = 0; 
WaveHeader.lpNext = 0;

if ((err = waveInOpen(&WaveInHandle, WAVE_MAPPER,
&WaveFormat, (DWORD)&waveInProc, 0, CALLBACK_FUNCTION))) 
{
	printf("Error opening the device!\n"); 
}

		if ((waveInPrepareHeader(WaveInHandle, &WaveHeader, sizeof(WaveHeader))))
		{ 
			printf("Error while preparing header!\n");
		} 

if((err = waveOutOpen(&WaveOutHandle,WAVE_MAPPER,&WaveFormat,(DWORD)&waveOutProc,0,CALLBACK_FUNCTION)) != MMSYSERR_NOERROR)
{
	printf("Error opening WaveOut!");
}

if((err = waveOutPrepareHeader(WaveOutHandle,&WaveHeader,sizeof(WaveHeader))))
{
	printf("Error while preparing waveOut Header");
}

if ((waveInAddBuffer(WaveInHandle, &WaveHeader, sizeof(WaveHeader))))
{ 
	printf("Error while adding buffer to queue!\n");
}

waveInStart(WaveInHandle);

getchar();

waveInClose(WaveInHandle);
printf("Device closed...\n\n\n");

return 0;

}