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