开发者

How to Copying a folder in VC++?

How to copy a folder from one drive to other drive in VC++ ...?

I have come this fa开发者_开发知识库r

   String^ SourcePath = Directory::GetCurrentDirectory();
   String^ DestinationPath = "c:\\Test";
   CString s(SourcePath) ;
   CString d(DestinationPath);
   Directory::CreateDirectory(DestinationPath);

 SHFILEOPSTRUCT*  pFileStruct = new SHFILEOPSTRUCT;
 ZeroMemory(pFileStruct, sizeof(SHFILEOPSTRUCT)); 
 pFileStruct->hwnd  = NULL;
 pFileStruct->wFunc = FO_COPY;
 pFileStruct->pFrom = (LPCWSTR)s;//"D:\test_documents\test1.doc"; 
 pFileStruct->pTo =  (LPCWSTR)d; 
 pFileStruct->fFlags = FOF_SILENT  | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR ; 
 bool i = pFileStruct->fAnyOperationsAborted ;
 int status = SHFileOperation(pFileStruct);

 if(status == 0)
 {
           return true;
 }
 return false;

the status is showing 2 instead of zero , can some one tell me why..?


Usually a String^ points to a managed string object. The SHFILOPSSTRUCT must befilled with pointers to unmanaged wchar_t. So you must pin the strings and convert. You tried to use the CString class as conversion helper.

Use the PtrToStringChars instead to get valid strings in pTo and pFrom: http://msdn.microsoft.com/en-us/library/d1ae6tz5(VS.80).aspx

The read of the fAnyOperationsAborted member is not required for the operation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜