/**************************************************************************** * * FUNCTION: ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) * * PURPOSE: Concatenates two PIDLs * ****************************************************************************/ LPITEMIDLIST CShellPidl::ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) { LPITEMIDLIST pidlNew; UINT cb1; UINT cb2; if (pidl1) //May be NULL cb1 = GetSize(pidl1) - sizeof(pidl1->mkid.cb); else cb1 = 0; cb2 = GetSize(pidl2); pidlNew = CreatePidl(cb1 + cb2); if (pidlNew) { if (pidl1) memcpy(pidlNew, pidl1, cb1); memcpy(((LPSTR)pidlNew) + cb1, pidl2, cb2); } return pidlNew; }
// 合并两个PIDL,通常用于将父文件夹的全PIDL与它的子文件或文件夹对象的 // 相对PIDL合并,从而得到文件或者子文件夹的全PIDL // LPITEMIDLIST CShellOperator::ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) { UINT cb1 = 0; if (pidl1 != NULL) { cb1 = GetSize(pidl1) - sizeof(pidl1->mkid.cb); // pidl1所占字节数,不包括必须部分 } UINT cb2 = GetSize(pidl2); // pidl2所占字节数 LPITEMIDLIST pidlNew = CreatePidl(cb1 + cb2); //创建一个新的PIDL if (pidlNew != NULL) { if (pidl1 != NULL) { memcpy(pidlNew, pidl1, cb1); // 由pidl1所指内存区域复制cb1个字节到pidlNew所指内存区域 } // 由pidl2所指内存区域复制cb2个字节到pidlNew+cb1所指内存区域 memcpy(((LPSTR)pidlNew) + cb1, pidl2, cb2); } return pidlNew; }