I got a VC++ 6.0 program which is a windows service. After converting to VC++
.NET 2003 project and fixing some coding error. It can compile and looks work
fine. But when I run the service, it said program error and looks it cannot
get a thread from AfxGetThread function.
Below please find a code segment which I experience the error.
Any can help on this?
const CString NDSApp::SERV_NAME(_T("NDS Data Delivery"));
NDSApp::NDSApp()
:CNTService("NDS Data Delivery"){
m_pNDSSetting = new CRegKeyValuePair(APPNAME,SECTION);
}
NDSApp::~NDSApp()
{
if (m_pNDSSetting)
delete m_pNDSSetting;
//if (m_pMainWnd)
// delete m_pMainWnd;
}
BEGIN_MESSAGE_MAP(NDSApp, CWinApp)
//{{AFX_MSG_MAP(NDSApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// NDSApp message handlers
/////////////////////////////////////////////////////////////////////////////
// CNTServices controllers
void NDSApp::Run(DWORD argc, LPTSTR * argv) {
ReportStatus(SERVICE_START_PENDING);
CWinThread* pThread = AfxGetThread();
if(pThread==NULL)
pThread=AfxGetApp();
InitApplication();
if (pThread->InitInstance()) {
m_SysMgr.SystemStartup();
ReportStatus(SERVICE_RUNNING);
pThread->Run();
}
else
ReportStatus(SERVICE_STOPPED);
}
void NDSApp::Stop() {
m_SysMgr.SystemStop();
CWinThread* pThread = AfxGetThread();
pThread->PostThreadMessage(WM_QUIT, NULL, NULL);
ReportStatus(SERVICE_STOPPED);
}
void NDSApp::Pause() {
m_SysMgr.SystemPause();
}
BOOL NDSApp::InitInstance() {
AfxOleInit();
AfxEnableControlContainer();
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
pMainFrame->ShowWindow(SW_HIDE);
pMainFrame->UpdateWindow();
m_pMainWnd = pMainFrame;
return m_SysMgr.SystemInit();
}
int NDSApp::ExitInstance() {
int iRes = CWinApp::ExitInstance();
if (pLogger)
delete pLogger;
return iRes;
}