Hi
I want to play a sound using directsound. As you can see i'm stuck already.

#include <dsound.h>
#include <iostream>
using namespace std;
int main(void)

{//CREATE OBJECT
	LPDIRECTSOUND8 ppDS8;
 
	HRESULT hr = DirectSoundCreate8(NULL,  ppDS8 ,NULL);
	cout << hr;
	Sleep(2000);
}

I get the following error:
1>.\main.cpp(9) : error C2664: 'DirectSoundCreate8' : cannot convert parameter 2 from 'LPDIRECTSOUND8' to 'LPDIRECTSOUND8 *'

1. What is missing to get it to work?

2. What is the LPDIRECTSOUND8 doing and what use do i have of it?

3. What is returned to ppDS8?

4. Why can't i write DSDEVID_DefaultPlayback instead of NULL in the first parameter? The SDK documentation says i can:

NULL for the default device, OR one of the following values.

http://msdn.microsoft.com/en-us/library/bb219693(VS.85).aspx

5. I want to see what the function returns (hopefully DS_OK), is it going to do so right now? i mean hr is not declared. What type should it be?

If i replace the code with the following i get "1>.\main.cpp(9) : error C2078: too many initializers" error:

#include <dsound.h>
#include <iostream>
using namespace std;
int main(void)

{//CREATE OBJECT
	int ppDS8;
 
	HRESULT DirectSoundCreate8(NULL,  ppDS8 ,NULL);
	
	Sleep(2000);
}'

Im using vista business, visual c++ 2008 and directX SDK march 2009

Please can someone help me?

Recommended Answers

All 9 Replies

cannot convert parameter 2 from 'LPDIRECTSOUND8' to 'LPDIRECTSOUND8 *'

This probably means that parameter 2 is an output parameter and needs to be a pointer:

HRESULT hr = DirectSoundCreate8(NULL,  &ppDS8, NULL);

I do not know much about the DirectSound API, so that is the best I can help without pretending I know by reading MSDN. ;)

Thank you for the quick reply, Tom! I'm not too familiar with pointers.
now it says

1>main.obj : error LNK2028: unresolved token (0A00029E) "extern "C" long __stdcall DirectSoundCreate8(struct _GUID const *,struct IDirectSound8 * *,struct IUnknown *)" (?DirectSoundCreate8@@$$J212YGJPBU_GUID@@PAPAUIDirectSound8@@PAUIUnknown@@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>main.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall DirectSoundCreate8(struct _GUID const *,struct IDirectSound8 * *,struct IUnknown *)" (?DirectSoundCreate8@@$$J212YGJPBU_GUID@@PAPAUIDirectSound8@@PAUIUnknown@@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)

you have to link with the appropriate DirectX libraries. When you downloaded the DirectX SDK you also got a lot of sample programs. Look in them and they will tell you what libraries you need. Or you can just read MSDN to find that out.

Try this:

IDirectSound8* pDS8 = NULL;

HRESULT hr = DirectSoundCreate8(NULL, &pDS8, NULL);

And are you linking with the direct sound lib?

And are you linking with the direct sound lib?

No I am not. I have no idea how to do it either. I found in the SDK doc the name of it (Dxguid.lib)

Answer to Ancient Dragon:
When I downloaded the SDK I got some samples. none of them uses directsound :(

Look up the function you want in MSDN -- it will tell you what lib you need. Yes I know that link is for WinCE, but it also applies to desktop win32.

No I am not. I have no idea how to do it either.

here's how to do it:

- go to [project]-->[...... properties]
- go to [configuration properties]-->[linker]-->[input]
- click "Additional dependencies" and add your libs.

Answer to Ancient Dragon:
When I downloaded the SDK I got some samples. none of them uses directsound :(

I found several of them here (on my computer)
C:\Program Files (x86)\Microsoft DirectX SDK (August 2008)\Samples\C++\XAudio2\Bin\x86

I included the needed .lib file but then i get about 100 errors from within the Dsound.lib

I am at the edge of giving up now, I just want to play pcm data that isn't stored in a .wav file. I don't have access to the wav header because i'm going to decompress an unusual audio file into raw pcm. Is there an easier way? 5 hours of googling says no...

I got it working now! Thank you very much! It doesn't display DS_OK, just a simple zero but whatever...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.