3

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?

laurent
  • 88,262
  • 77
  • 290
  • 428
  • 4
    On a wild guess, could the `path[1]` variable be used as described in http://stackoverflow.com/questions/3274472/c-double-linked-list-with-abstract-data-type (see accepted answer)? – simon Jun 13 '12 at 07:23
  • possible duplicate of [Variable Sized Struct C++](http://stackoverflow.com/questions/688471/variable-sized-struct-c) – AndersK Jun 13 '12 at 08:08

1 Answers1

6

The one-element array path[1] at the end of that struct is 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 than sizeof(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 path to TCHARs (which are normal chars in older platforms and WCHARs in modern, Unicode-based Windowses), put yet another \0 at the end of the string, and you got the PCZZTSTR.

buc
  • 6,268
  • 1
  • 34
  • 51