PostQuitMessage Issue

Hi,

I have tried to automate my application through a small VB program.  This program runs fine except for when you press the quit button.  This button succesfully navigates to the designated function in my C++ code for my application but at this point it fails.  All that is in this function is PostQuitMessage(0);.  It is on this call that the application locks up, as well as the VB app locking up.  I have looked at the information for postquitmessage but it doesnt seem to give many clues.  The only part I found a little confusing is, the parameter that you pass has to be an application exit code.  Does this mean I have to define it somewhere before   Or do I have to have other functions or processes set up in order to post the message succesfully Finally, i am using VS2003, strangely enough I found when using a release build of my application, that the problem occured, however using the debug build (we're talking about the actual exe here) the problem didnt occur   Since this is just one line of code I am a bit perplexed here

Anyone

Thanks
Will


Answer this question

PostQuitMessage Issue

  • Kevin Remde

    Ok i have got it working in the original way with the post method call, however could you shed some light on the solution.


    As i have said before it works for a debug build but not a release build. first of all i am using VS2003

    So i looked in my project configuration and changed the general->project defaults->use of mfc option to use mfc in a shared dll, from use mfc in a static dll   It was previously set as shared dll for the debug build and static for the release build.  As yet i have not managed to find what the difference is between the two except that one works and one doesnt.  The change to shared dll in release build doesnt seem to affect the program any other way,

    Any ideas

    Will

  • pangwa

    incidently i just managed to get some sort of feedback and it says

    Unhandled exception at 0x74e50b87 in a7w.exe: 0xC0000005: Access violation reading location 0x74e50b87.

    does that help

    Will

  • bilalso

    What library are you using MFC/ATL

    Were do you press the quit button On the VB side or in you C++ application while the VB Client is running

    PostQuitMessage alone isn't the right thing to close a aplication. Usually you should use PostQuitMessage when your main window receives the WM_DESTORY message.

    The problem you have might be, that the message loop is exited, but the application still knows about a application using the automation interface and locks it.



  • MasterBrain007

    The library is MFC,
    The quit button is pressed in the VB app, this is supposed to exit the C++ application and the VB continues running.

    What do I need to do to exit the C++ application entirely then

    Thanks
    Will


  • Dave12349

    ok i think i am understanding you, but why am i posting, since all i want to do is close the application could i use SendMessage I'm not completely confident if this is even possible

    Will

  • Il-Sung MSFT

    I wrote everything that is worth to be mentioned.
    Read the psoting dated: 09-28-2005, 5:17 AM PST

  • Ink Sloth

    I have also noticed that when i create an object from the vb program this bit of code is used

    EnableAutomation();

    AfxOleLockApp();

    I have tried using the unlock command before the quit or destroy methods and its still has no effect!

    Will


  • Thomas D. Greer

    a7w.exe, being the name of the application not the vb program
  • G Corlett

    First: Did you used my hints Using WM_CLOSE, setting the object to nothing in the VB application.

    AfxOleUnlockApp() ist called whenever the object is released from the VB Client.
    Usually it is called in the destructor of the object.

    You might decide never to call AfxOleLockApp/AfxOleUnlockApp in this case you application will not terminate automagicaly when the last client that creates your app terminates.

    The usual way is, when CFrameWnd::OnClose is called the application checks if it can close with AfxOleCanExitApp, if not it hides the application by calling AfxOleSetUserCtrl(FALSE).  If it can close it destroys the main window and this causes the PostQuitMessage to be executed.

    If the application is just hidden and AfxOleUnlockApp is called again and the usage count reaches 0 the main window is finally destroyed due to the call of AfxOleOnReleaseAllObjects.

    HTH



  • jdavidw13

    Ok I tried the WM_QUIT, and it didnt work, i even tried WM_DESTROY and this did not work either.  The application appeared to be unaltered, except in the case of WM_DESTROY where, it froze, then when i closed the application manual by clicking the X in the top right hand corner, it did close but the process was still running !

    Any ideas

    Will


  • Rookie_KC

    In my eyes it is just luck, that it worked.

    The problem is that you are directly inside an RPC call from VB when you call ExitApplication. This might have a deep impact on the calling program. Termination in this way is not normal.
    Using PostMessage causes the effect, that the RPC call from VB is finished and later the message WM_CLOSE is fetched from the message queue and the programm terminates in a more stable state.
    HTH



  • Wardyahh

    Hi,

    We're back here again,

    trying to do a quit from a vb automation program.  The function it calls in my C++ code just has this line.

    AfxGetApp()->GetMainWnd()->PostMessage (WM_CLOSE);

    This works, in a way, but leaves the c++ exe process running!

    I need a way to end the process or to send a different message   Incidently WM_DESTROY doesnt work either!

    Will



  • DTMartin

    I do not know how your automatin objects lock the MFC application.
    If you want to exit the MFC application using PostQuitMessage is the wrong way.
    Use PostMessage WM_CLOSE to your main window.

    Usually the application can only close if there is no outstanding reference to any other ole client.
    So the WM_CLOSE will hide the application and when the object in the VB is set to nothing the application should close.

  • Cindy Girl

    Hey,

    No I didnt use your hints, at least not in the way you mentioned, I didnt realise that the code had to go inside the VB app, i thought u meant the C++ app.  Either, way i would like to avoid that,  I would just like to call myprogram.Quit, in the VB app, which calls the corresponding quit method in my C++ app to work.  I have gone to one extreme and used the ExitProcess call in the C++ app, this got rid of the C++ app, but the VB app froze up, citing automation error again.  I tried the CCmdTarget::ExternalDisconnect before the exitprocess call as well, but that didnt seem to work.  The cpp file i have in my c++ project, i have just noticed uses the CCmdTarget class anything in that

    Thanks

    Will

  • PostQuitMessage Issue