1. You need to make sure SHGetPathFromIDList() is succeeding.
2. You must zero out all windows structures before use. This avoids problems when you don't fill in all the members, as you are not in this case.
3. pFrom and pTo must be double null terminated.
4. Also make sure that SHBrowseForFolder() is succeeding.
Code:
char path[MAX_PATH + 1]; // Space provided for extra null terminator
if (SHGetPathFromIDList (pidl, path)) // Get path
{
// ******** file operation ************
path[lstrlen[path] + 1] = '\0'; // Double null terminate path
SHFILEOPSTRUCT fopstruct = { 0 }; // Zero out structure before use
fopstruct.hwnd = NULL; // parent wnd
fopstruct.wFunc = FO_COPY; // function
fopstruct.fFlags = 0; // flags
fopstruct.pFrom = path; // path of the object - double null terminated
fopstruct.pTo = "E:\\cookies\0"; // destination - double null terminated
BOOL foCheck = SHFileOperation (&fopstruct);
if (!foCheck) MessageBox(NULL, "SHFileOperation failed!", NULL, MB_ICONSTOP);
}
else
{
MessageBox(NULL, "SHGetPathFromIDList failed!", NULL, MB_ICONSTOP);
}
CoTaskMemFree(pidl); // Release pidl returned by SHBrowseForFolder