[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Problem creating DirectSound primary buffer

Asked by AlbertaBeef in C++ Programming Language, Windows Programming

Tags: DirectX, DirectSound, buffer, E_INVALIDARG

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.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
//Globals
LPDIRECTSOUND8 pDSound = NULL;
LPDIRECTSOUNDBUFFER pDsndPrimary = NULL;
LPDIRECTSOUNDBUFFER8 pDsndSecondary = NULL;
 
int InitDSound(HWND hWnd)
{
	HRESULT hr = CoInitialize(NULL);
 
	hr = DirectSoundCreate8(NULL,&pDSound,NULL);
	if(FAILED(hr))
		return 1;
 
	hr = pDSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL);
	if(FAILED(hr))
		return 1;
 
//The 'problem' portion of my DSound function
	//Set up the wave format
	WAVEFORMATEX wvf;
	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
	DSBUFFERDESC dsDesc;
	ZeroMemory(&dsDesc, sizeof(DSBUFFERDESC));
 
	dsDesc.dwSize = sizeof(dsDesc);
	dsDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
	dsDesc.guid3DAlgorithm = GUID_NULL;
	dsDesc.lpwfxFormat = &wvf;
	dsDesc.dwBufferBytes = 0;
	dsDesc.dwReserved = NULL;
	
	//Create the buffer
	hr = pDSound->CreateSoundBuffer(&dsDesc, &pDsndPrimary, NULL);
	if(FAILED(hr))
		return 1; //Here hr is equal to E_INVALIDARG and the program quits
 
	return 0;
}
[+][-]11/15/08 10:06 PM, ID: 22969788Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/21/08 01:27 AM, ID: 23011388Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C++ Programming Language, Windows Programming
Tags: DirectX, DirectSound, buffer, E_INVALIDARG
Sign Up Now!
Solution Provided By: ee_auto
Participating Experts: 1
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625