Thread: Troubles with SHFILEOPSTRUCT

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Troubles with SHFILEOPSTRUCT

    Code:
    // Copy the picture file to the system directory.
                ZeroMemory(&fop, sizeof(SHFILEOPSTRUCT));  // this is just for testing.
                fop.hwnd = hwnd;
                fop.wFunc = FO_COPY;
    
                //test
                //strcat(pPath2Pic, "\0");
    
                fop.pFrom = pPath2Pic;    //Path2Pic
    
                // Change path to new dir. with picture name and ext.
                strcpy(pCopyTo, "\0");
    
                //test
                strcat(DF.Path2SystemsDirSystemID, "\0");
    
                strcpy(pCopyTo, DF.Path2SystemsDirSystemID);
                strcat(pCopyTo, "\\");
                strcat(pCopyTo, pPartNumber);
                strcat(pCopyTo, pFileExt);
                strcat(pCopyTo, "\0");
    
                fop.pTo = pCopyTo;
                fop.fFlags = FOF_NOCONFIRMATION;    // Add flag FOF_NOCONFIRMATION  for no confirmation
                test = SHFileOperation (&fop);        // RETURNS 0 for SUCCESS, != 0 failure.
                //  Do not use GetLastError with the return values of this function.    
                if((fop.fAnyOperationsAborted) || test)
                {
                    MessageBox(NULL, "Error copying picture file!", "Error:", MB_OK);
                }
    Here is what the debugger says the values are:

    + pFrom 0x0048b0d8 "D:\__My_Users\_Jon\__My_Documents\Desktop\TF_VG_4 51T_SS_CENTER\450-110-Steel.jpg" const char *
    + pTo 0x0017f1d8 "d:\__Programming\__MSVS_Projects\Storefront Estimation Program_CURRENT\Data\Systems\system1\450-110-Steel.JPG" const char *

    The error message says otherwise:
    Troubles with SHFILEOPSTRUCT-error-jpg
    This path is the path to my project not the file. What gives?

    /edit
    fop.fAnyOperationsAborted = 1
    test = 5

    This occurs on the 6th iteration of this proceedure!
    Last edited by Bajanine; 06-02-2011 at 10:34 PM. Reason: forgot return values:
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  2. #2
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    I guess after looking at the error dialog again, I am not sure but it appears to me that this is saying it is trying to copy FROM the destination folder instead of the copy from dir. But the debugger values are correct! Just ignore my statement: "This path is the path to my project not the file."

    Thanks in advance.
    Last edited by Bajanine; 06-02-2011 at 10:48 PM. Reason: Try to make my post a bit clearer.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  3. #3
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    If I select 'yes' to the Copy file dialog it actually create a new sub-folder with the name of the jpg it is supposed to copy and also copies the jpg to this new sub-directory.
    So if my correct path is:
    D:\__Programming\__MSVS_Projects\Storefront Estimation Program_CURRENT\Data\Systems\system1
    and the file name is:
    450-110-Steel.JPG
    It copies the file to:
    D:\__Programming\__MSVS_Projects\Storefront Estimation Program_CURRENT\Data\Systems\system1\450-110-Steel.JPG\450-110-Steel.JPG
    When it should be:
    D:\__Programming\__MSVS_Projects\Storefront Estimation Program_CURRENT\Data\Systems\system1\450-110-Steel.JPG
    So I must have an error in the fop.pTo = pCopyTo; variable, but the debugger says it is correct. I thought that the ZeroMemory line and building the path right before assigning the variable to fop.pTo would assure that I wouldn't get some hard to find bug. Guess I was wrong ;(
    I also noticed it doesn't always fail on the 6th iteration sometimes it fails on the 5th or even the 8th pass.

    If the debugger says it is correct how do I go about finding out what is wrong?
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > strcat(pCopyTo, "\0");
    This does NOT make your string double null terminated, as specified by SHFILEOPSTRUCT Structure (Windows)

    buff[strlen(buff)+1] = '\0';
    is how you do this.

    However, this only works if you have one filename in the buffer.

    If you want something like
    file1\0file2\0file3\0\0
    you should invent your own "cat" function that can append to a buffer containing \0, and ending with \0\0
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Angry

    Oh crap! I have made this mistake before. Thanks Salem for keeping me humble!

    Maybe I should lay off of the cough syrup!
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin.get() Troubles
    By yukapuka in forum C++ Programming
    Replies: 19
    Last Post: 06-04-2008, 01:30 PM
  2. tic tac toe troubles...
    By mkylman in forum Game Programming
    Replies: 8
    Last Post: 09-16-2006, 06:44 PM
  3. NIC Troubles?
    By Bajanine in forum Tech Board
    Replies: 4
    Last Post: 05-16-2004, 04:45 PM
  4. .AVI troubles
    By Untitled1 in forum Tech Board
    Replies: 6
    Last Post: 10-26-2003, 10:39 AM
  5. having troubles
    By neandrake in forum C++ Programming
    Replies: 7
    Last Post: 03-07-2002, 09:31 PM