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;
}