当前位置 : 主页 > 编程语言 > c++ >

日志.VC

来源:互联网 收集:自由互联 发布时间:2021-06-23
1、 int WriteLog( char * _pcFullFileName, char * _pcWrite, int _iWriteLen, unsigned long * _pdwWritten){ HANDLE hLogFile = CreateFileA(_pcFullFileName, GENERIC_WRITE, FILE_SHARE_READ, 0 , OPEN_ALWAYS /* CREATE_NEW */ , 0 , 0 ); // ZC: 存在

1、

int WriteLog(char* _pcFullFileName, char* _pcWrite, int _iWriteLen, unsigned long * _pdwWritten)
{
    HANDLE hLogFile = CreateFileA(_pcFullFileName, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS/*CREATE_NEW*/, 0, 0);// ZC: 存在:打开;不存在:创建
    if (hLogFile == INVALID_HANDLE_VALUE)
        return GetLastError();

    if (INVALID_SET_FILE_POINTER == SetFilePointer(hLogFile, 0, 0, FILE_END))
    {
        int iErr = GetLastError();
        CloseHandle(hLogFile);
        return iErr;
    }

    BOOL B = WriteFile(hLogFile, _pcWrite, _iWriteLen, _pdwWritten, NULL);
    if (!B)
    {
        int iErr = GetLastError();
        CloseHandle(hLogFile);
        return iErr;
    }
    CloseHandle(hLogFile);
    return 0;
}

 

2、

3、

4、

5、

网友评论