VC++6用API编的一个工程,结构如下:.
winmain()----->InitApp()----->winProc()------message loop
                    |
                    |-------->timeSetEvent()--->updateframe()运行时timeSetEvent()已经正确调updateframe().但是退出时,固定的出现错误对话框:"0x0040157e"指令引用的"0xdeadbf0b"内存,该内存不能为"read".
俺退出的具体方法:按一指定键后,PostMessage(hWnd, WM_CLOSE, 0, 0)消息.
WinMain()的具体内容:
int PASCAL WinMain(.... )
{   
    MSG                         msg;
    if (InitApp(hInstance, nCmdShow) != DD_OK)   return FALSE;
    SetTimerCallback( 40 );//内含timeSetEvent()
    while (TRUE)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
        {
            if (!GetMessage(&msg, NULL, 0, 0))
                return msg.wParam;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
            WaitMessage();
     }
     timeKillEvent(wTimerID);
}
俺的目标:按一热键启动定时,同时开始updateframe().俺是菜鸟,
不知道该怎样办?
   
    

解决方案 »

  1.   

    timeKillEvent(wTimerID);该放到哪个位置才正确呢?
      

  2.   

    猜测,在DispatchMessage(&msg);中得到WM_DESTROY了,系统退出timekillevent就出错了,尝试把它放在despatchmessage的callback winproc的wm_destroy中。
      

  3.   

    你的 timeKillEvent(wTimerID);脱离了消息循环,应该放到回调函数的消息处理中去。
    另外SetTimerCallback( 40 );这是什么搞不太懂,
      

  4.   

    SetTimerCallback()是我自己定义的一个函数,里面有timeSetEvent(),40是定时值40毫秒.