Windows Mobile 6.5

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

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


[in] Indicates the type of sound event to query for.


[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


Retrieve sound files or directories from the storage card.


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


Retrieve sound files from ROM.


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


[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.


[out] A pointer to an integer which indicates the number of SNDDIRECTORYINFO structures created and returned in ppSoundDirectories.

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

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.

The following code example demonstrates how to use SndGetSoundDirectoriesList.

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.

Windows Embedded CEWindows CE 5.0 and later
Windows MobilePocket PC for Windows Mobile Version 5.0 and later, Smartphone for Windows Mobile Version 5.0 and later