大概过程是这样的,我和远程服务器相连,得到一个文件名称strRead:
BYTE byRecv[MAX_PATH] = {0};
DWORD dwRecv = m_SocketManager.ReadComm( byRecv, MAX_PATH, INFINITE);
CString strRead(byRecv);strRead的字符串类型为"'***.***'"我去掉"'"
strRead.Replace(_T("'"),_T(""));然后得到当前创建的路径为strfilePath :
CString strfilePath = _T("");
strfilePath.Format(_T("%s\\Picture\\%s"), m_strfilePath, strRead);
其中m_strfilePath为exe运行路径然后
CFile file;
if(file.Open(strfilePath, CFile::modeCreate|CFile::modeWrite))
这里错误,不能创建这个文件,这是为什么?谢谢
BYTE byRecv[MAX_PATH] = {0};
DWORD dwRecv = m_SocketManager.ReadComm( byRecv, MAX_PATH, INFINITE);
CString strRead(byRecv);strRead的字符串类型为"'***.***'"我去掉"'"
strRead.Replace(_T("'"),_T(""));然后得到当前创建的路径为strfilePath :
CString strfilePath = _T("");
strfilePath.Format(_T("%s\\Picture\\%s"), m_strfilePath, strRead);
其中m_strfilePath为exe运行路径然后
CFile file;
if(file.Open(strfilePath, CFile::modeCreate|CFile::modeWrite))
这里错误,不能创建这个文件,这是为什么?谢谢
byRecv是ansi编码的,我的程序是unicode
--------------------------
AfxMessageBox(strfilePath);输出来看看是什么不就清楚了
你的byRecv要手动转换成unicode再赋值给CString
如何调整呢?byRecv是 ansi
但CString strRead(byRecv);之后strRead应该是Unicode吧 难道我理解错了?
CString strfilePath=_T("E:\111.bmp");打开文件能行吗?
CString strRead(byRecv); CString strfilePath = _T("");
strfilePath.Format(_T("c:\\%s"), strRead); CFile file;
if(file.Open(strfilePath, CFile::modeCreate|CFile::modeWrite))
{
int i = 0;
}测试时没问题的,一直能打开
try
{
CFile file;
file.Open(...);
...
}
catch(CFileException* e)
{
e->ReportError();
e->Delete();
}
后把字符串结束标志给改了
_tcscpy(tmp,strfilePath.GetBuffer());
CFile file;
if(file.Open(strfilePath, CFile::modeCreate|CFile::modeWrite))比如我这儿是,'.'也是wchar
- tmp 0x0039e610 "c:\11.bmp" wchar_t [1024]
[0] 99 L'c' wchar_t
[1] 58 L':' wchar_t
[2] 92 L'\' wchar_t
[3] 49 L'1' wchar_t
[4] 49 L'1' wchar_t
[5] 46 L'.' wchar_t
[6] 98 L'b' wchar_t
[7] 109 L'm' wchar_t
[8] 112 L'p' wchar_t
[9] 0 wchar_t
非常感谢您,我找到错误了 ,现在已经ok了 以前那个字符地址中有\r\n作为结束符,这个字符导致地址无效。结贴了