Hi,
I created a little app that just shows a modal dialog window with a message for the users to wait while the OS is installing devices. In the OnInitDialog function from the dialog window a thread is started which checks if there are pending install events and closes the dialog window when there are no more of these... It's at this point the app crashes sometimes. Here is some code to explain more in detail:
I hope someone sees what I'm doing wrong. Maybe the worker thread is not closed properly?
Thx in advance,
RaKKeR
I created a little app that just shows a modal dialog window with a message for the users to wait while the OS is installing devices. In the OnInitDialog function from the dialog window a thread is started which checks if there are pending install events and closes the dialog window when there are no more of these... It's at this point the app crashes sometimes. Here is some code to explain more in detail:
Code:
// USBWaitDlg.cpp : implementation file
//
#include "stdafx.h"
#include "USBWait.h"
#include "USBWaitDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//this is the thread that calls the waiting function
UINT CUSBWaitDlg::ThreadWaitInstalling(LPVOID params){
CUSBWaitDlg * me = (CUSBWaitDlg *)params;
me->WaitInstalling();
return 0;
}
//this is the waiting function
void CUSBWaitDlg::WaitInstalling(){
HINSTANCE hCfgMgr; //Handle to cfgmgr32.dll
CMP_WaitNoPendingInstallEvents func;
DWORD ret;
hCfgMgr = LoadLibrary("C:\\windows\\system32\\cfgmgr32.dll");
Sleep(1000);
if(hCfgMgr != 0){
func = (CMP_WaitNoPendingInstallEvents)GetProcAddress(hCfgMgr,"CMP_WaitNoPendingInstallEvents");
ret = (*func)((DWORD)100);
while(ret == WAIT_TIMEOUT){
//AfxMessageBox("Busy installing",0,0);
ret = (*func)((DWORD)100);
}
}
EndDialog(IDOK); //I think the crash happens after this call...
}
CUSBWaitDlg::CUSBWaitDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUSBWaitDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUSBWaitDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CUSBWaitDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUSBWaitDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUSBWaitDlg, CDialog)
//{{AFX_MSG_MAP(CUSBWaitDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CUSBWaitDlg::OnInitDialog()
{
CDialog::OnInitDialog();
AfxBeginThread(&ThreadWaitInstalling,(LPVOID)this);
return TRUE;
}
void CUSBWaitDlg::OnPaint()
{
CDialog::OnPaint();
}
I hope someone sees what I'm doing wrong. Maybe the worker thread is not closed properly?
Thx in advance,
RaKKeR