Problem ending application

This is a discussion on Problem ending application within the C Programming forums, part of the General Programming Boards category; I am very new to C. I have created an application that calls a DLL. The DLL is used to ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    2

    Problem ending application

    I am very new to C. I have created an application that calls a DLL. The DLL is used to create a dialog with a bunch of labels and edit boxes on them. On the dialog is a Quit button. The DLL handles this as well. When the Quit button is clicked, I need to close the entire application, the dialog as well and the parent form. Here's what I have so far:

    Code:
    LRESULT CALLBACK ParseDialogProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
      static HWND hWndChild;
      char* cBuffer;
      int iLength;
      const int iMaxBufferSize = 500;
      char sMsgBuffer[iMaxBufferSize];
    
      switch(message)
      {
        case WM_INITDIALOG:
          hWndChild = (HWND)GetParent(hWnd);
          break;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
              case btnParse:
       //there is some code here but it all works so i omitted it
              case btnExit:	
                SendMessage(hWndChild,WM_CLOSE,NULL,NULL);
                break;		
            }
            break;
          default:
            return DefWindowProc(hWnd,message,wParam,lParam);
          break;
      }
    return 0;
    }
    When I debug, it hits the SendMessage(hWndChild, WM_CLOSE,NULL,NULL) line, then goes to the return line. And I get this error then: Unhandled exception in ParseName.exe: 0xC0000005: Access Violation.
    Last edited by rbrodbeck; 07-17-2008 at 11:56 AM.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Handle WM_CLOSE.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    2
    What do you mean?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Add something like:
    Code:
    case WM_CLOSE:
    to your switch statement above, and let it do the necessary operations to exit the application.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    26
    Is there a reason your not using MFC? It was created to make life easier (and handles all this stuff for you), rather than the complex method which you seem to be using.

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    242
    You are sending the WM_CLOSE message but you are not handling it; don't expect it to close the window by it's own.
    Code:
    switch(message)
    {
    case WM_CLOSE:
     DestroyWindow(hwnd);
    break;
    }
    ---
    Mole42, it's important to understand how API works before working with MFC.
    Last edited by eXeCuTeR; 07-17-2008 at 03:33 PM.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by Mole42 View Post
    Is there a reason your not using MFC? It was created to make life easier (and handles all this stuff for you), rather than the complex method which you seem to be using.
    This is C, not C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cleanup of the application...
    By Petike in forum Windows Programming
    Replies: 1
    Last Post: 08-16-2008, 06:23 PM
  2. problem with A simple modeless messagebox
    By hanhao in forum C++ Programming
    Replies: 8
    Last Post: 07-06-2005, 12:18 AM
  3. Dev Resource problem
    By algi in forum Windows Programming
    Replies: 3
    Last Post: 04-19-2005, 04:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21