I’m having a look at the code of FastCopy. I want to add some option so that files are deleted to the recycle bin instead of permanently.
The first issue I came across is the way paths are stored – as a BYTE[1] type. I thought it might be some pointer pointing to the real path, but probably not if it’s just one byte. See below for the full structure:
struct MoveObj {
_int64 fileID;
_int64 fileSize;
enum Status { START, DONE, ERR } status;
DWORD dwFileAttributes;
BYTE path[1];
};
Any idea what it means?
My second issue is that I need to convert this string to some scary MS type called “PCZZTSTR” so that it can be used with a SHFILEOPSTRUCT structure. Any suggestion how I could do this conversion?
The one-element array
path[1]at the end of thatstructis just a general C trick to implement variable sized structures. Prior to the C99 standard, variable-sized structures were not permitted in the C language, so programmers implemented it this way.The byte sequence that stores the path begins at the first element of that array (
path[0]), but more memory is allocated for the structure thansizeof(MoveObj), so the array itself is more than one byte long. If the length of the array is not stored in the struct, I guess it’s zero-terminated.PCZZTSTR may sound scary, but essentially it’s just a simple C-style string of
TCHARs, which is terminated with two'\0'characters. P (pointer to a), CZ (C-style, zero-terminated) Z (doubly zero-terminated), T (TCHAR), STR (string).You have to convert the bytes in
pathtoTCHARs (which are normalchars in older platforms andWCHARs in modern, Unicode-based Windowses), put yet another\0at the end of the string, and you got thePCZZTSTR.