Domanda

I have a question involving SHFileOperation:

    SHFILEOPSTRUCT sf2;
    memset(&sf2,0,sizeof(sf2));
    sf2.hwnd = NULL;
    sf2.wFunc = FO_DELETE;
    sf2.fFlags = FOF_NOCONFIRMATION;
    sf2.pFrom = pathSubDir; // where pathSubDir = ""

    //2. Delete temporary files
    int n = SHFileOperation(&sf2);

My expectation was that since pathSubDir was "", it wasn't deleting anything and that I should get n NOT equal to 0. But, that was not the case. I ended up with n = 0, which means that the operation was completed successfully. I was curious as to if someone could explain to me why my assumptions are wrong. Thank you.

È stato utile?

Soluzione

The API requires pFrom to be double-null-terminated. A simple empty string like "" doesn't qualify. The API could be reading whatever memory comes after the first null character and successfully deleting those files.

Another explanation, if your string is really formatted correctly, is that the API has successfully deleted all the requested files, and encountered no failures along the way. It accomplished all the deletions you asked for, so it returns success.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top