回忆.初作项目时遇到的第一个绞尽脑汁的问题.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://testTo0");


/*
 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("复制失败!!!"));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值