TCHAR szPath[MAX_PATH];
GetModuleFileName( NULL, szPath, MAX_PATH );
PathRemoveFileSpec( szPath );
CString strFile = szPath;
CString strDatFilePath;
strDatFilePath.Format( _T("%s\\%s"),strFile, RECORD_FILE);
if(PathFileExists(strDatFilePath))
{
DeleteFile(strDatFilePath);
}
HANDLE hFile = NULL;
DWORD dwWritten;
hFile = CreateFile(strDatFilePath,GENERIC_ALL,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile == INVALID_HANDLE_VALUE)
return S_FALSE;
WORD header = 0xFEFF;
if(!WriteFile(hFile,&header,2,&dwWritten,NULL))
{
return FALSE;
}
if(INVALID_SET_FILE_POINTER == SetFilePointer(hFile,0,NULL,FILE_END))
{
return FALSE;
}
WriteFile(hFile,str,str.GetLength() * sizeof(TCHAR),&dwWritten,NULL);
CloseHandle(hFile);
保存文本文件为Unicode格式
最新推荐文章于 2022-05-19 20:36:35 发布