문제

Windows CE 4.2 및 MS Embedded VC ++ 4.0을 사용하고 있습니다. 다음 코드는 나에게 오류를 제공합니다 Access to [file name] was denied., 파일을 생성하지만 아무것도 쓰지 않습니다.

CString tmp;
tmp.Format(_T("%s%d"), mFileName, ++ctr);
TRY 
{
  mFile.Open(tmp, CFile::modeCreate);
  mFile.Write(&data[ctr%2], 1);
  mFile.Close();
}
CATCH (CException, e)
{
  TCHAR szCause[255];
  CString strFormatted;

  e->GetErrorMessage(szCause, 255);
  strFormatted += szCause;
  AfxMessageBox(strFormatted);
}
END_CATCH

흥미롭게도, 사용 CreateFile 잘 작동 :

CString tmp;
tmp.Format(_T("%s%d"), mFileName, ++ctr);

hFile = CreateFile(tmp, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL /*| FILE_FLAG_WRITE_THROUGH*/, 0);
WriteFile(hFile, &(data[ctr%2]), 1, &bytesWritten, NULL);
CloseHandle(hFile);

왜 이것이 될 수 있습니까? Wince에서 cfile을 사용할 수 있습니까? 나는 방금 내장 된 개발로 시작합니다.

도움이 되었습니까?

해결책

Windows CE에서는 MFC를 사용하지 않았지만 일반 Windows에서는 일반적인 관용구가

  mFile.Open(tmp, CFile::modeCreate|CFile::modeWrite);

즉 생성자에 "cfile :: modewrite"를 추가하십시오. MSDN 문서는 이것이 필요하다는 것을 시사합니다.

Bitwise 또는 (|) 연산자를 사용하여 아래 나열된 옵션을 결합 할 수 있습니다. 하나의 액세스 권한과 하나의 공유 옵션이 필요합니다. modecreate 및 modenoinherit 모드는 선택 사항입니다.

이것은 나에게 "중재"또는 "modewrite"중 하나가 항상 공급되어야 함을 의미합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top