Microsoft Docs – DirectSoundCreate

Function Overview

DirectSoundCreate creates a DirectSound object used for playing and capturing audio.

HRESULT DirectSoundCreate( LPCGUID pcGuidDevice, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter );

Available Since: DirectX 3.0

Parameters

ParameterTypeDescription
pcGuidDeviceLPCGUIDPointer to GUID of the sound device. Use NULL for default device.
ppDSLPDIRECTSOUND *Address of a pointer that receives the DirectSound interface pointer.
pUnkOuterLPUNKNOWNMust be NULL (DirectSound does not support aggregation).

Return Value

Returns an HRESULT indicating success or failure.

Remarks

Before calling any DirectSound methods, you must call DirectSoundCreate to obtain a DirectSound object. After creation, use IDirectSound::SetCooperativeLevel to set the priority.

For multi‑device environments, retrieve device GUIDs via DirectSoundEnumerate.

Example

#include <dsound.h> #pragma comment(lib, "dsound.lib") int main() { LPDIRECTSOUND pDS = nullptr; HRESULT hr = DirectSoundCreate(NULL, &pDS, NULL); if (FAILED(hr)) { // handle error return -1; } // Set cooperative level hr = pDS->SetCooperativeLevel(GetConsoleWindow(), DSSCL_PRIORITY); // ... use DirectSound pDS->Release(); return 0; }