SHFileOperation with FOF_WANTMAPPINGHANDLE ??
Posted on 2000-03-02
Can somebody tell me what is wrong with this piece of code??
pShNM doesn't points to an SHNAMEMAPPING struct
memset(&shfo, 0x00, sizeof(shfo));
shfo.hwnd = AfxGetMainWnd()->m_hWnd;
shfo.wFunc = FO_COPY;
shfo.pFrom = from;
shfo.pTo = to;
shfo.fFlags = FOF_RENAMEONCOLLISION|FOF_WANTMAPPINGHANDLE;
if (0 == ::SHFileOperation(&shfo))
// try to obtain a pointer
// to the first (and in this
// case the only)
// SHNAMEMAPPING struct of the
// structure pointed to by
// THIS IS THE PROBLEM: pShNM doesn't point to an
// SHNAMEMAPPING struct when the file being operated on
// was renamed by the file system
SHNAMEMAPPING* pShNM = (SHNAMEMAPPING*)((char*)shfo.hNameMappings + sizeof(int));
The docs say the following: "Treat hNameMappings as a pointer to a structure whose first member is an INT value, followed by an array of SHNAMEMAPPING structures. The INT value will be set to the number of structures in the array. Each SHNAMEMAPPING structure will contain the old and new path name for one of the renamed files."
The first member of the struct pointed to by SHFILEOPSTRUCT.hNameMappings (the number of SHNAMEMAPPING structs that will follow this int value) seems correct but the bytes that follow this integer value are just junk ... and not an SHNAMEMAPPING struct
Environment: NT4 SP5 IE5.0
(maybe it's something trivial but I don't know what I'm doing wrong)