回憶.初作項目時遇到的第一個絞盡腦汁的問題.wchar_t*

Visual Studio 2005好可惡,以下是我試過N種方式解決,因爲文件路徑問題引起的CString to wchar_t*

/*
 char szSP[] = "J://testFrom//*.*";
 char szDP[] = "J://testTo///";

 char szSourcePath[strlen(szSP)+2];
 char szDestinationPath[strlen(szDP)+2];

 memset(szSourcePath, 0, sizeof(szSourcePath));
 memset(szSourcePath, 0, sizeof(szDestinationPath));

 szSourcePath = szSP;
 szDestinationPath = szDP;
 */

 

 CString strSourcePath;
 CString strDestinationPath;

 strSourcePath = _T("J://testFrom//*.*///0");
 strDestinationPath = _T("J://testTo////0");


/*
 wchar_t * szSourcePath = A2W(strSourcePath);
 wchar_t * szDestinationPath = A2W(strDestinationPath);
*/
 /*
 wchar_t * szSourcePath;
 wchar_t * szDestinationPath;

 szSourcePath = (wchar_t *)strSourcePath.GetString();
 szSourcePath = (wchar_t *)strDestinationPath.GetString();
*/
  /*
 szSourcePath = (wchar_t *)strSourcePath.AllocSysString();
 szDestinationPath = (wchar_t *)strDestinationPath.AllocSysString();
*/
 
 wchar_t * szSourcePath = (wchar_t *)((LPCTSTR)strSourcePath);
 wchar_t * szDestinationPath = (wchar_t *)((LPCTSTR)strDestinationPath);


/*
//!!!!!!!!!!
 wchar_t * szSourcePath = _T("J://testFrom//*.*");
 wchar_t * szDestinationPath = _T("J://testTo//");
*/

/*
 wchar * szSourcePath = _T("J://testFrom//*.*");
 wchar * szDestinationPath = _T("J://testTo//");
*/
/*
 char * szSourcePath = "J://testFrom//*.*/0";
 char * szDsestinationPath = "J://testTo///0";
 */
 /*
 wchar_t * szSourcePath = (wchar_t *)(strcat((LPCTSTR)strSourcePath, _T("/0")));
 wchar_t * szDestinationPath = (wchar_t *)(strcat((LPCTSTR)strDestinationPath, _T("/0")));
 */
 /*
 wchar_t wcsSourcePath[wcslen(szSourcePath) + 1] = _T("");
 wchar_t wcsDestinationPath[wcslen(szDestinationPath) + 1] = _T("");

 wcscpy(wcsSourcePath, szSourcePath);
 wcscpy(wcsDestinationPath, szDestinationPath);
*/

 /*
 
 wchar_t * szSourcePath = _T("J://testFrom//*.*");
 wchar_t * szDestinationPath = _T("J://testTo//");
 */

 /*
 wchar_t * szZero = _T("/0");

 wcscat(szSourcePath, szZero);
 wcscat(szDestinationPath, szZero);
*/
/*
 wcscat(szSourcePath, _T("/0"));
 wcscat(szDestinationPath, _T("/0"));
*/

/*
 wcscat(szSourcePath, 0);
 wcscat(szDestinationPath, 0);
*/
 SHFILEOPSTRUCT FileOP; //SHFILEOPSTRUCT聲明
 ZeroMemory(&FileOP, sizeof(FileOP));

 //SHFILEOPSTRUCT成員賦值
 FileOP.hwnd = AfxGetApp()->m_pMainWnd->m_hWnd;
 FileOP.fFlags = FOF_SILENT;
 FileOP.wFunc = FO_COPY;


 FileOP.pFrom = szSourcePath;
 //FileOP.pFrom = strSourcePath;


 FileOP.pTo = szDestinationPath;
 //FileOP.pTo = strDestinationPath;


 FileOP.fAnyOperationsAborted = FALSE; //
 FileOP.hNameMappings = NULL;
 FileOP.lpszProgressTitle = NULL;
 //SHFILEOPSTRUCT成員賦值結束

 int msg = SHFileOperation(&FileOP);//執行復制操作

 if(msg==0)
   AfxMessageBox(_T("複製完成"));

    else
  AfxMessageBox(_T("複製失敗!!!"));

發佈了7 篇原創文章 · 獲贊 1 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章