kuang Cao
March 15th, 2006, 11:07 AM
Hi,
I am working on a feature as described below:
1. Use the GetOpenFileName() to select a file in a directory and open the file.
2. The user can then make changes to the content of the file.
3. Based on the changes, all the files in the same directory as the opened file will be renamed, as well as the containing directory.
Now here comes the problem, I had no problem renaming all the files, even the file that was opened, but when I tried to rename the containing directory, it failed with a share violation.
I then tried some sample code from a book, but the same thing happened even if I just select a file but don't do anything with the file, i.e, not opening the file.
The following is the relevant sample code for selecting the file:
ofn.lStructSize = sizeof (OPENFILENAME) ;
ofn.hwndOwner = hwnd ;
ofn.hInstance = NULL ;
ofn.lpstrFilter = szFilter ;
ofn.lpstrCustomFilter = NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.nFilterIndex = 0 ;
ofn.lpstrFile = pstrFileName ;
ofn.nMaxFile = MAX_PATH ;
ofn.lpstrFileTitle = pstrTitleName ;
ofn.nMaxFileTitle = MAX_PATH ;
ofn.lpstrInitialDir = NULL ;
ofn.lpstrTitle = NULL ;
ofn.Flags = 0 ; // Set in Open and Close functions
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0 ;
ofn.lpstrDefExt = TEXT ("txt") ;
ofn.lCustData = 0L ;
ofn.lpfnHook = NULL ;
ofn.lpTemplateName = NULL ;
ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
GetOpenFileName (&ofn) ;
Thanks a lot for your help.
I am working on a feature as described below:
1. Use the GetOpenFileName() to select a file in a directory and open the file.
2. The user can then make changes to the content of the file.
3. Based on the changes, all the files in the same directory as the opened file will be renamed, as well as the containing directory.
Now here comes the problem, I had no problem renaming all the files, even the file that was opened, but when I tried to rename the containing directory, it failed with a share violation.
I then tried some sample code from a book, but the same thing happened even if I just select a file but don't do anything with the file, i.e, not opening the file.
The following is the relevant sample code for selecting the file:
ofn.lStructSize = sizeof (OPENFILENAME) ;
ofn.hwndOwner = hwnd ;
ofn.hInstance = NULL ;
ofn.lpstrFilter = szFilter ;
ofn.lpstrCustomFilter = NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.nFilterIndex = 0 ;
ofn.lpstrFile = pstrFileName ;
ofn.nMaxFile = MAX_PATH ;
ofn.lpstrFileTitle = pstrTitleName ;
ofn.nMaxFileTitle = MAX_PATH ;
ofn.lpstrInitialDir = NULL ;
ofn.lpstrTitle = NULL ;
ofn.Flags = 0 ; // Set in Open and Close functions
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0 ;
ofn.lpstrDefExt = TEXT ("txt") ;
ofn.lCustData = 0L ;
ofn.lpfnHook = NULL ;
ofn.lpTemplateName = NULL ;
ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
GetOpenFileName (&ofn) ;
Thanks a lot for your help.