设置了断点,单步调试和直接运行为什么结果不一样?

_Tiny 2013-05-25 10:31:43
UINT CaptrueThread(LPVOID lpParm )
{
CCaptrueForMFCDlg *dlg = (CCaptrueForMFCDlg*)lpParm;
dlg->m_bCapture1 = true;
dlg->m_bCapture2 = false;
CString strfilename;
strfilename = _T("Data/config.ini");
while(!dlg->m_bTerminateCaptureThread)
{
if (dlg->m_bCapture1)
{
dlg->OpenCapture1();
CString strconfig;
GetPrivateProfileString("Capture2Info", "strc2", "", strconfig.GetBuffer(MAX_PATH), MAX_PATH, "Data/config.ini");
int bs = strconfig.GetLength();
strconfig.ReleaseBuffer();
if ( !(strconfig.Find("on")) )
{
EnterCriticalSection(&g_cs);
dlg->m_bCapture1 = false;
dlg->m_bCapture2 = true;
LeaveCriticalSection(&g_cs);
}
}


if (dlg->m_bCapture2)
{
dlg->OpenCapture2();
}


}
return 0;
}


然后在OpenCapture2()中SetTimer(2 ,10000, NULL);
OnTimer中
	if (nIDEvent == 2)
{
EnterCriticalSection(&g_cs);
m_bPicture = true;
m_bCapture = false;
LeaveCriticalSection(&g_cs);
}

等了10秒,没有任何反映在OnTimer中设了断点也没进来,我觉得没有什么问题啊。还麻烦帮忙看看什么情况~[/quote] 单步调试执行了if (nIDEvent == 2)之后的语句,但是直接运行的时设置断点根本没有进入OnTimer,这个是什么问题,该怎么处理呢???
...全文
569 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
_Tiny 2013-05-27
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
有时只有通过写日志到文件才能找到错误的根源;通过其它手段(包括单步、断点、显示日志到屏幕、……)都不行! 写日志参考这个: //1-78行添加到你带main的.c或.cpp的那个文件的最前面 //81-85行添加到你的main函数开头 //89-93行添加到你的main函数结束前 //在要写LOG的地方仿照第87行的写法写LOG到文件MyLog1.log中 [/code]
非常详细,万分感激,我试试看。谢谢了。
赵4老师 2013-05-27
  • 打赏
  • 举报
回复
有时只有通过写日志到文件才能找到错误的根源;通过其它手段(包括单步、断点、显示日志到屏幕、……)都不行! 写日志参考这个:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
    #include <windows.h>
    #include <io.h>
#else
    #include <unistd.h>
    #include <sys/time.h>
    #include <pthread.h>
    #define  CRITICAL_SECTION   pthread_mutex_t
    #define  _vsnprintf         vsnprintf
#endif
//Log{
#define MAXLOGSIZE 20000000
#define MAXLINSIZE 16000
#include <time.h>
#include <sys/timeb.h>
#include <stdarg.h>
char logfilename1[]="MyLog1.log";
char logfilename2[]="MyLog2.log";
static char logstr[MAXLINSIZE+1];
char datestr[16];
char timestr[16];
char mss[4];
CRITICAL_SECTION cs_log;
FILE *flog;
#ifdef WIN32
void Lock(CRITICAL_SECTION *l) {
    EnterCriticalSection(l);
}
void Unlock(CRITICAL_SECTION *l) {
    LeaveCriticalSection(l);
}
#else
void Lock(CRITICAL_SECTION *l) {
    pthread_mutex_lock(l);
}
void Unlock(CRITICAL_SECTION *l) {
    pthread_mutex_unlock(l);
}
#endif
void LogV(const char *pszFmt,va_list argp) {
    struct tm *now;
    struct timeb tb;

    if (NULL==pszFmt||0==pszFmt[0]) return;
    _vsnprintf(logstr,MAXLINSIZE,pszFmt,argp);
    ftime(&tb);
    now=localtime(&tb.time);
    sprintf(datestr,"%04d-%02d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);
    sprintf(timestr,"%02d:%02d:%02d",now->tm_hour     ,now->tm_min  ,now->tm_sec );
    sprintf(mss,"%03d",tb.millitm);
    printf("%s %s.%s %s",datestr,timestr,mss,logstr);
    flog=fopen(logfilename1,"a");
    if (NULL!=flog) {
        fprintf(flog,"%s %s.%s %s",datestr,timestr,mss,logstr);
        if (ftell(flog)>MAXLOGSIZE) {
            fclose(flog);
            if (rename(logfilename1,logfilename2)) {
                remove(logfilename2);
                rename(logfilename1,logfilename2);
            }
        } else {
            fclose(flog);
        }
    }
}
void Log(const char *pszFmt,...) {
    va_list argp;

    Lock(&cs_log);
    va_start(argp,pszFmt);
    LogV(pszFmt,argp);
    va_end(argp);
    Unlock(&cs_log);
}
//Log}
int main(int argc,char * argv[]) {
    int i;
#ifdef WIN32
    InitializeCriticalSection(&cs_log);
#else
    pthread_mutex_init(&cs_log,NULL);
#endif
    for (i=0;i<10000;i++) {
        Log("This is a Log %04d from FILE:%s LINE:%d\n",i, __FILE__, __LINE__);
    }
#ifdef WIN32
    DeleteCriticalSection(&cs_log);
#else
    pthread_mutex_destroy(&cs_log);
#endif
    return 0;
}
//1-78行添加到你带main的.c或.cpp的那个文件的最前面
//81-85行添加到你的main函数开头
//89-93行添加到你的main函数结束前
//在要写LOG的地方仿照第87行的写法写LOG到文件MyLog1.log中
mujiok2003 2013-05-26
  • 打赏
  • 举报
回复
 if (dlg->m_bCapture2)
这个判断成立吗?
_Tiny 2013-05-26
  • 打赏
  • 举报
回复
引用 1 楼 mujiok2003 的回复:
说明timerId不正确。 trace一下nIDEvent 或者干脆不检查nIDEvent试试。
……trace这是as3的吧,我设置断点到nIDEvent那里,他的值是正确的,而且我不判断也是这样子的~
mujiok2003 2013-05-25
  • 打赏
  • 举报
回复
说明timerId不正确。 trace一下nIDEvent 或者干脆不检查nIDEvent试试。

64,439

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧