Click here to Skip to main content
15,923,689 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: multi-select in CTreeCtrl Pin
Tibor Blazko18-Jul-02 23:02
Tibor Blazko18-Jul-02 23:02 
GeneralDownloading file Pin
Anonymous18-Jul-02 19:54
Anonymous18-Jul-02 19:54 
GeneralRe: Downloading file Pin
Roman Nurik18-Jul-02 20:33
Roman Nurik18-Jul-02 20:33 
GeneralRe: Downloading file Pin
Anonymous18-Jul-02 21:13
Anonymous18-Jul-02 21:13 
GeneralRe: Downloading file Pin
Scott H. Settlemier19-Jul-02 7:23
Scott H. Settlemier19-Jul-02 7:23 
GeneralRe: Downloading file Pin
Michael Dunn19-Jul-02 16:54
sitebuilderMichael Dunn19-Jul-02 16:54 
GeneralSHFileOperation failed, why. Pin
ttzzgg_8071318-Jul-02 19:47
ttzzgg_8071318-Jul-02 19:47 
GeneralRe: SHFileOperation failed, why. Pin
Mike Upton18-Jul-02 22:40
Mike Upton18-Jul-02 22:40 
If you have a look in the documentation for SHFILEOPSTRUCT, you'll see that pFrom and pTo both need to be double null terminated strings, which the std::string::c_str() operator won't give you.

A couple of minor points too - you should really initialise the entire SHFILEOPSTRUCT structure, and your code isn't UNICODE safe (but I'm assuming that's not an issue for you).

So, one possible version of this code would be (N.B. code is untested):

BOOL AppFileOperator(LPCSTR lpszSrc, LPCSTR lpszDest, int op)
{
  SHFILEOPSTRUCT stFileOP={0};
 
  //allow space for double terminating null
  char* pFrom = new char[strlen(lpszSrc)+2];
  char* pTo = new char[strlen(lpszDest)+2];
 
  //strncpy will pad the copied string with nulls up to the length
  //specified, so no need to add the terminating nulls separately.
  strncpy(pFrom, lpszSrc, strlen(lpszSrc)+2);
  strncpy(pTo, lpszDest, strlen(lpszDest)+2);
 
  stFileOP.pFrom = pFrom;
  stFileOP.pTo = pTo;
  stFileOP.wFunc = op;
  stFileOP.fFlags = FOF_SILENT | FOF_NOCONFIRMATION;
 
  printf("Start to file operator.\n src file : %s,\n dest file is %s\n", lpszSrc, lpszDest);
 
  BOOL bSuccess = (SHFileOperation(&stFileOP) == 0);
 
  delete[] pFrom;
  delete[] pTo;
 
  return bSuccess;
}




"We are the knights who say Ni" (The Knights Who Say Ni)
GeneralRe: SHFileOperation failed, why. Pin
ttzzgg_8071319-Jul-02 1:51
ttzzgg_8071319-Jul-02 1:51 
Generalwave file editing please help me Pin
anju18-Jul-02 18:10
anju18-Jul-02 18:10 
GeneralEvents in edit control Pin
harish kota18-Jul-02 17:52
harish kota18-Jul-02 17:52 
GeneralRe: Events in edit control Pin
includeh1018-Jul-02 23:14
includeh1018-Jul-02 23:14 
GeneralEvents in edit control Pin
KVHK18-Jul-02 17:52
KVHK18-Jul-02 17:52 
GeneralRe: Events in edit control Pin
Chris Losinger18-Jul-02 18:02
professionalChris Losinger18-Jul-02 18:02 
GeneralRe: Events in edit control Pin
harish kota18-Jul-02 18:41
harish kota18-Jul-02 18:41 
QuestionCan i use CSocket in thread? Pin
gandi18-Jul-02 15:29
gandi18-Jul-02 15:29 
AnswerRe: Can i use CSocket in thread? Pin
Nish Nishant18-Jul-02 15:42
sitebuilderNish Nishant18-Jul-02 15:42 
GeneralRe: Can i use CSocket in thread? Pin
gandi18-Jul-02 15:57
gandi18-Jul-02 15:57 
AnswerRe: Can i use CSocket in thread? Pin
Anonymous19-Jul-02 3:01
Anonymous19-Jul-02 3:01 
AnswerRe: Technically possible, but... Pin
Masaaki Onishi19-Jul-02 9:42
Masaaki Onishi19-Jul-02 9:42 
QuestionWhich user interface? Pin
Steve L.18-Jul-02 14:58
Steve L.18-Jul-02 14:58 
AnswerRe: Which user interface? Pin
Gary Kirkham18-Jul-02 15:29
Gary Kirkham18-Jul-02 15:29 
GeneralRe: Which user interface? Pin
Steve L.18-Jul-02 16:05
Steve L.18-Jul-02 16:05 
GeneralRe: Which user interface? Pin
ColinDavies18-Jul-02 21:39
ColinDavies18-Jul-02 21:39 
GeneralListView Pin
Anthony988718-Jul-02 14:18
Anthony988718-Jul-02 14:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.