I tried Sleep(1) but it looks like win xp and win 2000 wait for 10 ms instead. I could be wrong but if I do Sleep(10) then delay between characters I am sending exactly as with Sleep(1). I am not a Windows programmer, I am specialising in embedded real-time and particular in Unix systems and I know that often default kernel time resolution is 10 ms (eg. linux). What resolution windows Xp, 2000, 95, 98 have? Are they the same? What the best way to sleep for 1 ms? Thank you
leatrop
Posts
-
What the best way to sleep 1 ms -
CDialog::EndDialog crashes applicationHmm.., ((ProgressDialog *)lparam)->PostMessage(WM_COMMAND,IDOK) fixes the problem, but what was wrong with EndDialog?! Stack trace: USER32! 77d562cf() CDialog::EndDialog(int) ReadDeviceThread(void *) _threadstart(void *) KERNEL32!7c80b50b() ---------------------------- ProgressDialog.cpp ---------------------------- // ProgressDialog.cpp : implementation file // #include "stdafx.h" #include "monitor.h" #include "ProgressDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // ProgressDialog dialog ProgressDialog::ProgressDialog(CWnd* pParent /*=NULL*/) : CDialog(ProgressDialog::IDD, pParent) { //{{AFX_DATA_INIT(ProgressDialog) m_text = _T(""); //}}AFX_DATA_INIT } void ProgressDialog::OnFinalRelease() { // When the last reference for an automation object is released // OnFinalRelease is called. The base class will automatically // deletes the object. Add additional cleanup required for your // object before calling the base class. CDialog::OnFinalRelease(); } void ProgressDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ProgressDialog) DDX_Control(pDX, IDC_MPROGRESS, m_bar); DDX_Text(pDX, IDC_MPROGTEXT, m_text); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(ProgressDialog, CDialog) //{{AFX_MSG_MAP(ProgressDialog) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ProgressDialog message handlers int ProgressDialog::DoModal(char *txt) { m_text = txt; //m_bar.SetRange(0,100); //m_bar.SetPos(0); return CDialog::DoModal(); } void ProgressDialog::SetText(char *txt) { m_text = txt; UpdateData(FALSE); } void ProgressDialog::SetPos(int pos) { m_bar.SetPos(pos); } void ProgressDialog::OnCancel() { // TODO: Add extra cleanup here StopAcc = 0; CancelProgressModal = 1; Sleep(4); // a little delay to stop a collision CDialog::OnCancel(); } void ProgressDialog::SetRange(int min, int max) { m_bar.SetRange(min, max); } ---------------------------- ProgressDialog.h ---------------------------- #if !defined(AFX_PROGRESSDIALOG_H__13AB40A1_4F1A_11D2_932F_F4950FC10000__INCLUDED_) #define AFX_PROGRESSDIALOG_H__13AB40A1_4F1A_11D2_932F_F4950FC10000__INCLUDED_ #include "stdafx.h" #include "resource.h" #if _MSC_VER >= 1000 #pragma once #endi
-
CDialog::EndDialog crashes applicationThank you khan++ - PostMessage has fixed the problem. I still wondered what was wrong with EndDialog??!!
-
CDialog::EndDialog crashes applicationI have pretty simple code void ReadDeviceThread( void *lparam ) { Sleep(2000); ((ProgressDialog *)lparam)->EndDialog(IDOK); } void CMainWindow::OnReadDevice() { static ProgressDialog pd; _beginthread(ReadDeviceThread, 0, &pd); pd.DoModal("Initialising read from device"); } The app crashes at user32.dll (win XP, VC++ 6.0, SP6.0) after call of EndDialog. Specifically it crashes after calling ::EndDialog at the end of the EndDialog routine. void CDialog::EndDialog(int nResult) { ASSERT(::IsWindow(m_hWnd)); if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL)) EndModalLoop(nResult); ::EndDialog(m_hWnd, nResult); // after this line app crashes at USER32! 77d562cf() } Could anybody please help me with this problem. What's wrong with my code. Thank you