Access Violation when creating a dialog in a C++ console app 
Author Message
 Access Violation when creating a dialog in a C++ console app

I have a C++ console app that I have added a dialog to. When I call
DoModal() for the dialog it makes to the OnInitDialog funciton and
then I get:

---------------------------
Microsoft Visual C++
---------------------------
Unhandled exception in MDMCommandShell.exe: 0xC0000005: Access
Violation.
---------------------------
OK  
---------------------------

Clicking OK brings me to the following line (from WINCORE.CPP):

// pump message, but quit on WM_QUIT
if (!AfxGetThread()->PumpMessage())
{
        AfxPostQuitMessage(0);
        return -1;

Quote:
}

Anyone have any idea how I can fix this? (Let me know if I need to
post more info)

NOTE: I typically never do any GUI programming so though this is not
new to me I have mostly forgotten how it all comes together.



Tue, 31 May 2005 23:11:16 GMT  
 Access Violation when creating a dialog in a C++ console app
DoModal won't work because a console app has no message pump. MessageBox works (see my
essay) because MessageBox contains its very own message pump. There is no good fix for
this. You could create a UI thread and run the dialog out of that, but this introduces
even more complexities.
                        joe


Quote:
>I have a C++ console app that I have added a dialog to. When I call
>DoModal() for the dialog it makes to the OnInitDialog funciton and
>then I get:

>---------------------------
>Microsoft Visual C++
>---------------------------
>Unhandled exception in MDMCommandShell.exe: 0xC0000005: Access
>Violation.
>---------------------------
>OK  
>---------------------------

>Clicking OK brings me to the following line (from WINCORE.CPP):

>// pump message, but quit on WM_QUIT
>if (!AfxGetThread()->PumpMessage())
>{
>    AfxPostQuitMessage(0);
>    return -1;
>}

>Anyone have any idea how I can fix this? (Let me know if I need to
>post more info)

>NOTE: I typically never do any GUI programming so though this is not
>new to me I have mostly forgotten how it all comes together.

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Wed, 01 Jun 2005 07:08:28 GMT  
 Access Violation when creating a dialog in a C++ console app

Quote:

>// pump message, but quit on WM_QUIT
>if (!AfxGetThread()->PumpMessage())
>{

The most simple way to go from a console application to some gui
application is to create an MFC application which dialog based.

The wizard generates lots of code, for you the important thing is the
initinstance method of the C<your name>App class:

there the generated code displays the dialog box and sets the
m_pMainWnd pointer. You can easily modifiy this to create an invisible
window set the pointer and there you have your message pump!

Just call the main() from you console application afterwards and
you're done.

HTH

---
Thomas Gawehns
www.softwaremeister.com/daily_backup.html
daily backup changed/new files into zip archives



Wed, 01 Jun 2005 10:42:54 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Access violations once OCBC/CRecordset added to console app

2. Create modeless dialog box in console app

3. Create modeless dialog box in console app

4. Is there a way to create Console App in Visual C++ 7.0 like older Ver 6.0

5. Release Version: Access Violation: ?theApp@@3VCMyApp@@A (Multithread App)

6. Access Violation porting app to NT4.0

7. [ Access violation sending message in multi-threaded app! ]

8. Help: Crash when loading MFC 4.2 dll's in VC6 app (Access violation)

9. Access violations in Visual C 5 Apps

10. Release Version: Access Violation: ?theApp@@3VCMyApp@@A (Multithread App)

11. MFC app getting access violation in NTDLL.DLL

12. access violation creating singleton instance

 

 
Powered by phpBB® Forum Software