在c ++文件重新创建文件后,写入文件的权限会丢失。 [英] Write permission of a file getting lost after file recreation in c++.

查看:74
本文介绍了在c ++文件重新创建文件后,写入文件的权限会丢失。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我有一个有2个exes的MFC应用程序。它们共享一个用于读写的公共资源文件。一旦文本文件超出其大小限制,它就会被重新创建。之后只有一个exes能够写入文件。即娱乐后写入权限会丢失

I have an MFC application which has 2 exes. They share a common resource file for reading and writing.Once the text file exceeds its size limit it gets recreated. After that only one of the exes is able to write to file. ie write permission is getting lost after recreation.

下面是用于创建新文件的代码段。

below is the piece of code used for creating the new file.

CreateFile( m_szLogFileName,GENERIC_ALL,FILE_ALL_ACCESS,NULL,OPEN_ALWAYS | OPEN_EXISTING | CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

CreateFile(m_szLogFileName, GENERIC_ALL, FILE_ALL_ACCESS, NULL, OPEN_ALWAYS|OPEN_EXISTING|CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

您能否提出任何解决方案。在此先感谢。

Can you suggest any solution. Thanks in advance.

推荐答案

您是否考虑使用
SetEndOfFile 截断文件而不是重新创建?

Have you considered to truncate the file using SetEndOfFile instead of re-creation?


这篇关于在c ++文件重新创建文件后,写入文件的权限会丢失。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆