游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2687|回复: 11

不知道什么错误

[复制链接]

16

主题

158

帖子

168

积分

注册会员

Rank: 2

积分
168
发表于 2004-7-13 15:42:00 | 显示全部楼层 |阅读模式
我写了一个用来作LOG文件的方法,输出文件是log.html,为什么这个类在MFC下面调试通过,在directdraw下却不能写进内容?
代码如下:
头文件:
#pragma once
const char* const LOG_FILE_NAME = "Log.html";
const char* const LOG_FLAG = "</FONT></BODY></HTML>";
const int LOG_OFFSET = -21;      //文件末尾21个字符,也就是--                                              //"</FONT></BODY></HTML>"
//html内容
const char* const LOG_CONTENT = "<HTML><HEAD><TITLE>Log Message</TITLE></HEAD>\
<BODY><Font COLOR=\"#405090\"><B>LOG<HR COLOR=\"#405090\">START ! ......<BR><BR>\
</FONT></BODY></HTML>";

class CLog
{
public:
        CLog(void);
        ~CLog(void);
        static int OutPutToLog(const char* const p_StrMsg,bool p_IsErrMsg);

};

CPP文件:
#include ".\log.h"

CLog::CLog(void)
{
}

CLog::~CLog(void)
{
}

//
// p_IsErrMsg为true时,输出红色字体,表示错误信息
//
int CLog::OutPutToLog(const char* const p_StrMsg,bool p_IsErrMsg)
{
        int fh, nbytes;            //fh : file handle
                                   //nbytes : file length
        time_t ltime;
        ltime = time(NULL);

//=====1: Get the FileLength====================
        fh = _open(LOG_FILE_NAME, _O_TEXT | _O_CREAT | _O_WRONLY);
        //O_RDONLY : if the file is not exit,create the file
        if( fh == -1 )
        {
                _close(fh);
                return -1;
        }
       
        nbytes= _filelength(fh);
       
        //if new file input the content
        if (!(nbytes>0))
        {
                _write(fh,LOG_CONTENT,(int)strlen(LOG_CONTENT));
        }

        _close(fh);

        //2pen again and input the log message
        fh = _open(LOG_FILE_NAME, _O_TEXT | _O_WRONLY);
        if( fh == -1 )
        {   
                _close(fh);
                return -1;
        }

        _lseek(fh,LOG_OFFSET,SEEK_END);

        if(p_IsErrMsg)
        {
                _write(fh,"<Font color = red>",18);
                //_write(fh,strTime,(int)strlen(strTime));
                _write(fh,ctime(&ltime),(int)strlen(ctime(&ltime)));
                _write(fh," : ",3);
                _write(fh,p_StrMsg,(int)strlen(p_StrMsg));
                _write(fh,"<BR></font>",11);
                _write(fh,LOG_FLAG,(int)strlen(LOG_FLAG));
        }
        else
        {
                //_write(fh,strTime,(int)strlen(strTime));
                _write(fh,ctime(&ltime),(int)strlen(ctime(&ltime)));
                _write(fh," : ",3);
                _write(fh,p_StrMsg,(int)strlen(p_StrMsg));
                _write(fh,"<BR>",4);
                _write(fh,LOG_FLAG,(int)strlen(LOG_FLAG));
        }
               
        _close(fh);

        return 0;
}

16

主题

158

帖子

168

积分

注册会员

Rank: 2

积分
168
 楼主| 发表于 2004-7-13 15:46:00 | 显示全部楼层

Re:不知道什么错误

少加了几个头文件
#include <fcntl.h>
#include <io.h>
#include <time.h>
#include <windows.h>

1万

主题

1万

帖子

2万

积分

管理员

中级会员

Rank: 9Rank: 9Rank: 9

积分
20527
发表于 2004-7-13 15:46:00 | 显示全部楼层

Re:不知道什么错误

在DDraw下应该不会对文件的读写操作有影响,可能是你代码哪里有误。

16

主题

158

帖子

168

积分

注册会员

Rank: 2

积分
168
 楼主| 发表于 2004-7-13 15:49:00 | 显示全部楼层

Re:不知道什么错误

在MFC下调试这个类很正常啊,一点都没有事,但在ddraw下面log文件是建成了,但是错误信息写不进去,不知道为什么。

50

主题

992

帖子

1012

积分

金牌会员

Rank: 6Rank: 6

积分
1012
发表于 2004-7-13 16:30:00 | 显示全部楼层

Re:不知道什么错误

直接写文件不好吗?速度快

16

主题

158

帖子

168

积分

注册会员

Rank: 2

积分
168
 楼主| 发表于 2004-7-13 21:34:00 | 显示全部楼层

Re:不知道什么错误

我也就在几个关键的地方加上,想看看程序运行的信息

37

主题

378

帖子

388

积分

中级会员

Rank: 3Rank: 3

积分
388
QQ
发表于 2004-7-13 22:03:00 | 显示全部楼层

Re:不知道什么错误

你可能是因为缺少MFC当中的某些支持吧……这个有可能会有编译错误,也有可能什么也没有,但是有运行错误……建议你还是别用html了

16

主题

158

帖子

168

积分

注册会员

Rank: 2

积分
168
 楼主| 发表于 2004-7-14 11:56:00 | 显示全部楼层

Re:不知道什么错误

我又测试了一下,窗口模式下也是正常的。
文件读写和全屏还是窗口模式无关的吧?

16

主题

158

帖子

168

积分

注册会员

Rank: 2

积分
168
 楼主| 发表于 2004-7-14 11:59:00 | 显示全部楼层

Re:不知道什么错误

错了,是debug模式下可以,release模式下不行,求助什么原因,是不是我哪个函数用错了?

3

主题

17

帖子

17

积分

新手上路

Rank: 1

积分
17
发表于 2004-7-14 14:40:00 | 显示全部楼层

Re:不知道什么错误

将 char* 全部改为 char[];

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-7-3 20:09

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表