thanks, i found out the problem, it lies inside the constructor. the problem is solved after i removed the 'if section' code. does it mean i cant have an if statement inside constructor??? CTAMADlg::CTAMADlg(CWnd* pParent /*=NULL*/) : CDialog(CTAMADlg::IDD, pParent) { //{{AFX_DATA_INIT(CTAMADlg) m_hDevice = INVALID_HANDLE_VALUE; m_hClose = INVALID_HANDLE_VALUE; m_hClose = CreateEvent (NULL, TRUE, FALSE, NULL); if ( m_hClose == INVALID_HANDLE_VALUE ) { MessageBox("Thread event error!","Error",MB_OK); } //}}AFX_DATA_INIT m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }