Share via


SndGetSoundDirectoriesList

4/8/2010

This function returns an array of possible directories for sound files for the specified sound event type and memory location.

Syntax

HRESULT SndGetSoundDirectoriesList(
   SND_EVENT seSoundEvent,
   DWORD grfLocations, 
   SNDDIRECTORYINFO** ppSoundDirectories,
   int* pcSoundDirectories
);

Parameters

  • seSoundEvent
    [in] Indicates the type of sound event to query for.
  • grfLocations
    [in] Indicates locations in memory that are searched for sound directories. The following table shows the bitmask values for this parameter, with a description of the purpose of each.

    Bitmask Description

    SND_LOCATION_STORAGECARD

    Retrieve sound files or directories from the storage card.

    SND_LOCATION_USERDATA

    Retrieve sound files from user data folders such as \My Documents and \Application Data\Sounds or \Storage Application Data.

    SND_LOCATION_ROM

    Retrieve sound files from ROM.

    SND_LOCATION_ALL

    Retrieves sound files from all locations - storage card, user data folders, and ROM.

  • ppSoundDirectories
    [out] A pointer to an array of sound directories. This function will create the array of SNDDIRECTORYINFO structures, and allocate the appropriate amount of memory.
  • pcSoundDirectories
    [out] A pointer to an integer which indicates the number of SNDDIRECTORYINFO structures created and returned in ppSoundDirectories.

Return Value

The function may return any HRESULT and the application should use the SUCCEEDED and FAILED macros to check the results.

Remarks

This function enables an application to query directories where sound files should be copied to for any of the sound events listed in the SND_EVENT enumeration. The fully qualified path for the directory is returned. This function allocates memory for all SNDDIRECTORYINFO structures as one contiguous block. The user is responsible for freeing all memory returned by this function by calling LocalFree function on the returned pointer.

Code Example

The following code example demonstrates how to use SndGetSoundDirectoriesList.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

void CopyAndSetRingtone(TCHAR* pszCurrentDirectory, TCHAR* pszFileName)
{
    TCHAR szPathAndFile[MAX_PATH];
    TCHAR szDestination[MAX_PATH];
    // Initialize an empty SNDFILEINFO structure.
    SNDFILEINFO sndFile               = {0};
    SNDDIRECTORYINFO* pSndDirectories = NULL;
    int cSoundDirectories             = 0;
    // Build the path to the file.
    StringCchPrintf(szPathAndFile, MAX_PATH, _T("%s\\%s"), pszCurrentDirectory, pszFileName);
    // Get the list of User Data directories.
    SndGetSoundDirectoriesList(SND_EVENT_RINGTONELINE1, SND_LOCATION_USERDATA, &pSndDirectories, &cSoundDirectories);
    // Set the destination to the first User Data directory.
    StringCchPrintf(szDestination, MAX_PATH, _T("%s\\%s"), pSndDirectories->szPathName, pszFileName);
    CopyFile(szPathAndFile, szDestination, FALSE);
    // Setup values in the SNDFILEINFO structure.
 only need to set sndFile.szPathName, not sndFile.szDisplayName.
    sndFile.sstType = SND_SOUNDTYPE_FILE;
    StringCchCopy(sndFile.szPathName, MAX_PATH, szDestination);
    // Set the ringtone.
    SndSetSound(SND_EVENT_RINGTONELINE1, &sndFile, TRUE);
    // Free memory.
    LocalFree(pSndDirectories);
    return;
}

Requirements

Header soundfile.h
Windows Embedded CE Windows CE 5.0 and later
Windows Mobile Pocket PC for Windows Mobile Version 5.0 and later, Smartphone for Windows Mobile Version 5.0 and later

See Also

Concepts

Sounds Reference