Thursday, November 15, 2007

Determine the path of special folders

Here’s one method to determine the path of special folders (e.g. the Desktop folder, the Start Menu folder, etc).

      #include 
      #include 
 

LPITEMIDLIST pidl;

HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl);

if (SUCCEEDED(hr))

{

// Convert the item ID list's binary

// representation into a file system path

char szPath[_MAX_PATH];

if (SHGetPathFromIDList(pidl, szPath))

{

AfxMessageBox(szPath );

}

else

{

ASSERT(FALSE);

}

}

else

{

ASSERT(FALSE);

}

For a list of CSIDL values corresponding to different special folders, please refer “CSIDL Values” in MSDN documentation.

No comments: