944,093 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 7046
  • C++ RSS
Nov 28th, 2004
0

Visual C++ program compiles, but won't run

Expand Post »
I am working on a time card program in Visual C++ (FYI: I am VERY new to this, so, please, be gentle with me) It compiles with 0 errors and 0 warnings, but when it executes I get an error message that the program needs to close. When I tried to go into Debug, it gave me "Unhandled exception in MFCTimeCard.exe:0XC0000005: Access Violation" I click on OK and it goes to this piece of code in the AfxWinMain()

if (!pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)
{
TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
pThread->m_pMainWnd->DestroyWindow();
}
nReturnCode = pThread->ExitInstance();
goto InitFailure;
}
nReturnCode = pThread->Run();

Please let me know if anyone needs more info. BTW: I did not touch this particular bit when working. I did however add the InitInstance() in a source file.
THANKS!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reagan is offline Offline
5 posts
since Nov 2004
Nov 28th, 2004
0

Re: Visual C++ program compiles, but won't run

The real error will be in the InitInstance() method.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 28th, 2004
0

Re: Visual C++ program compiles, but won't run

That is kinda what I figured, but I've looked it over a dozen times Here is my code:

BOOL CTimeCardApp::InitInstance() {
CTimeCard time;
time.DoModal();
return FALSE;
}
Thanks!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reagan is offline Offline
5 posts
since Nov 2004
Nov 29th, 2004
0

Re: Visual C++ program compiles, but won't run

Doesn't returning false signify failure? I dunno, I'm not an MFC guy. If that's not the problem, then time is crashing on init.
Reputation Points: 13
Solved Threads: 2
Newbie Poster
glSuccinct is offline Offline
13 posts
since Aug 2004
Nov 30th, 2004
0

Re: Visual C++ program compiles, but won't run

I think you're onto something.
Where is the CTimeCard initialised?
What is it anyway? If it's a reference to something else you're calling a method on an uninitialised object which will indeed cause an access violation.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 4th, 2004
0

Re: Visual C++ program compiles, but won't run

Got it! I forgot to put in the a line to instantiate the application object. Thanks for your help!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reagan is offline Offline
5 posts
since Nov 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ Data Types
Next Thread in C++ Forum Timeline: Setting double to infinity





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC