我可以使用共享读写吗?

use*_*527 6 c windows fopen file

我可以在C中创建一个可以在用户模式下随时访问的文件吗?

我的意思是

    zwcreatefile(...shareread||sharewrite...)
Run Code Online (Sandbox Code Playgroud)

我可以在用户模式下使用fopen吗?

我希望我的日志文件可以共享读写,所以当我的程序运行时,我仍然可以打开它并查看日志,而我的程序仍然写在那里.

use*_*527 5

#include <stdlib.h>
#include <stdio.h>
#include <share.h>
#include <stdlib.h>

FILE *FPlogHigh; 

int main(int argc, char **argv)
{   
    FPlogHigh = _fsopen("filename.txt", "a+",_SH_DENYWR);
    if (FPlogHigh)
    {
        fprintf(FPlogHigh,"\nHello log started\n");
        fclose(FPlogHigh);
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

每次我想在那里写入时,我都会打开和关闭文件句柄。它允许我从任何其他程序访问日志文件。当此 1 写入日志文件但关闭 FCLOSE(); 时,我也无法更改其他程序中的日志。我可以编辑 a+ 代表追加,每次打开文件时它都会写入到文件末尾。