Problem creating DirectSound primary buffer

I'm trying to learn how to use DirectSound so that I can use it in a game engine I am working on. I'm using MSVC++ 2008 (Without MFC) and the DXSDK March 2008.

The problem I am having is that when I attempt to create the primary buffer using the IDirectSound8::CreateSoundBuffer function the returned HRESULT is always E_INVALIDARG. Since I am relatively inexperienced with C++ chances are it's a quick-fix solution, but I've searched MSDN, Google and Experts-Exchange and I've found nothing to help me.

Thanks in advance.
int InitDSound(HWND hWnd)
	HRESULT hr = CoInitialize(NULL);
	hr = DirectSoundCreate8(NULL,&pDSound,NULL);
		return 1;
	hr = pDSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL);
		return 1;
//The 'problem' portion of my DSound function
	//Set up the wave format
	ZeroMemory(&wvf, sizeof(WAVEFORMATEX));
	wvf.nChannels = 1;
	wvf.wFormatTag = WAVE_FORMAT_PCM;
	wvf.nSamplesPerSec = 11025;
	wvf.wBitsPerSample = 16;
	wvf.nBlockAlign = ((wvf.nChannels*wvf.wBitsPerSample)/8);
	wvf.nAvgBytesPerSec = (wvf.nBlockAlign*wvf.nSamplesPerSec);
	wvf.cbSize = 0;
	//Create the buffer description
	ZeroMemory(&dsDesc, sizeof(DSBUFFERDESC));
	dsDesc.dwSize = sizeof(dsDesc);
	dsDesc.guid3DAlgorithm = GUID_NULL;
	dsDesc.lpwfxFormat = &wvf;
	dsDesc.dwBufferBytes = 0;
	dsDesc.dwReserved = NULL;
	//Create the buffer
	hr = pDSound->CreateSoundBuffer(&dsDesc, &pDsndPrimary, NULL);
		return 1; //Here hr is equal to E_INVALIDARG and the program quits
	return 0;

Open in new window

LVL 13
Glen A.IT Project ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Glen A.IT Project ManagerAuthor Commented:
This problem has been solved:

It seems that the lpwfxFormat member can't be specified in the DSBUFFERDESC structure when you are creating a buffer with the DSBCAPS_PRIMARYBUFFER flag.

This question can be closed.
Question PAQ'd, 500 points refunded, and stored in the solution database.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.