mfc >> Program Fail to Run After Convert from VC++ 6.0 to VC++ .NET 2003

by SmFtZXM » Mon, 20 Mar 2006 22:59:42 GMT

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;
}


Similar Threads

1. vc++ 6.0 or vc++ .net 2003?

After taking 2 semesters of C++ at school, I've decided to get a compiler for my personal use when not at school, and one that can do Windows programming.  I've pretty much come down to either vc++ .net 2003 standard or vc++ 6.0 pro.  Basically, my main reservations about .net 2003 is that from what I've read it lacks optimizations, but 6.0 seems to be more dated, "less standardized", and the support will expire soon.  Any opinions or help would be appreciated. Thanks in advance.

-Aaron

2. How to convert VC 6.0 Wizard to VC 7 (.net 2003) - Microsoft Visual C++/VC++

3. Basic Question About Moving From VC 6.0 to VC.NET 2003

Hi all,

If i compile my VC 6.0 code with the VC.NET 2003 compiler (unmanaged
C++), then can the compiled executable be run on a machine without the
.NET architecture?

Thanks!

4. VC 6.0 and VC.NET 2003 differences

5. VC++ 7.0 makes programs that run slower than VC++ 6.0

In both cases I am maximizing for speed, yet the new compiler produces code that 
takes 50% more time, is this inherent or do I need to change my optimization (or 
other) settings? 


6. VC++ .NET 2003 Pro and VC++ Toolkit 2003: Optmizing code

7. Upgrading VC 6.0 to VC 2003

I have an ATL COM object compiled with VC 6.0 that needs to be compiled in 
Visual Studio .Net 2003.  I got the project converted, compiled and linked 
without errors.  It registers correctly but it will not instatiate as an 
ActiveX control in my classic ASP pages.  I get the "ActiveX component can't 
create object" message.
What am I doing wrong?
Thanks,

8. VC++ 2003 compile time slower than VC++ 6.0