none
How to stop my driver when application crashes in wince 6 RRS feed

  • Question

  • Hi All,

    I have a camera driver running. My application is a huge module under development in C++. When the application crashes due to certain reason on field my camera still keeps on running. So i have to restart the device loosing important data.

     

    Is there a way to call function (camera stop) when ever the application crashes.

     

    Thanks

    Misbah

    Thursday, December 30, 2010 12:49 PM

All replies

  • Are you using DirectShow compatible camera driver or custom camera driver?
     
    If you are using Directshow camera driver then in your application exception handler try to stop the running filter graph.It will stop the camera operation.
    Thursday, December 30, 2010 1:02 PM
  • Thanks Prabu for your reply !

     

    I am using custom driver. (Stream interface driver)

     

    Can i do this in the application :-

    __except(EXCEPTION_EXECUTE_HANDLER)
    {
             RETAILMSG(ZONE_ERROR, (L"exception in application\r\n"));

           // Stop the camera

          if(FALSE == DeviceIoControl(m_hDevice, CAM_OV3640_STOP, &m_SelectedCam, sizeof(DWORD), &dwOutput, 0, &dwReturn,      (LPOVERLAPPED) NULL))
        {
            RETAILMSG(1, (L" Cam CAM_OV3640_STOP IOCTL failed !!!!\r\n"));
        }

    }

     

    --Misbah

    Thursday, December 30, 2010 1:07 PM
  • If it is a custom driver,then it is upto you to stop the camera running(i.e.,)You should call the approriate function of the camera driver for stopping.
     
    If you are able to find the location of the crash,then you can add those in that.Give it  a try.
    Thursday, December 30, 2010 1:28 PM
  • As i mentioned this a huge module developed my various programmers, finding the location of the crash is difficult.

     

    So i want to try adding a exception handler and stopping the camera inside the handler.

     

    I just know the module which is crashing. Is it possible to put the whole code under __try and __except block ?

     

    and stop the camera under __except()

     

    --Misbah

    Thursday, December 30, 2010 1:46 PM
  • Where is the data that you want?  In the application or in the driver?
    Thursday, December 30, 2010 3:57 PM
  • In the application.

    And i dont want to to change my driver for this reason.

     

    I want to do things in application.

     

    I even tried this as a sample application and it works . Please find it below :-

     

    Code snippet :-
    ---------------

    void CGUICamera::GetPictureCam(void)
    {
            DWORD                        dwReturn;
            char                        sStr[256],*ptr; // to crash the application
            FILE                        *fp;

    //        Sleep(1500);

    try
    {
            m_FrameParam.pCameraBuffer =
    malloc(m_DisplayConfig.SrcRect.right*m_DisplayConfig.SrcRect.bottom*2);
            if (!m_FrameParam.pCameraBuffer)
                    return;

    #ifdef UNDER_CE
            RETAILMSG(1, (L" GUICamCmds: Size allocated for storing picture:
    %d\r\n",(m_DisplayConfig.SrcRect.right*m_DisplayConfig.SrcRect.bottom*2)));

            if(FALSE == DeviceIoControl(m_hDevice, CAM_OV3640_GET_PICTURE, &m_SelectedCam,
    sizeof(DWORD), &m_FrameParam, sizeof(PUCHAR), &dwReturn, (LPOVERLAPPED) NULL))
            {
                    RETAILMSG(1, (L" Cam CAM_OV3640_GET_PICTURE IOCTL failed !!!!\r\n"));
            }
    #endif

            RETAILMSG(1,(L" Frame params are --> Time stamp %d,Camera Index %d Image size id
    ->%d\r\n",\
                    m_FrameParam.uFrameTimestamp,m_FrameParam.CameraIndex,dwReturn));

            sprintf(sStr, "Snap%dx%d_%d.yuyv", m_DisplayConfig.SrcRect.right,
    m_DisplayConfig.SrcRect.bottom, m_FrameParam.uFrameTimestamp);

            //fp = fopen(sStr,"w+"); //misbah
            //fwrite(m_FrameParam.pCameraBuffer,dwReturn,1,fp); //misbah
            //fwrite((PUCHAR) m_ImageCapture.Image,dwReturn,1,fp);
            //fclose(fp); //misbah

            *ptr = 1; //ERROR :: crash for testing

            free(m_FrameParam.pCameraBuffer);
            m_FrameParam.pCameraBuffer = NULL;

            throw(1);

    }
    catch(int i)
    {
            RETAILMSG(1, (L"exception in application\r\n"));
            HANDLE m_hDevice;
            DWORD        dwOutput;
            DWORD        dwReturn,dummy=0;
            m_hDevice = CreateFile(TEXT("COV1:"), GENERIC_READ|GENERIC_WRITE,
    FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,OPEN_EXISTING, 0, NULL);
            if(FALSE == DeviceIoControl(m_hDevice, CAM_OV3640_STOP, &dummy, sizeof(DWORD),
    &dwOutput, 0, &dwReturn, (LPOVERLAPPED) NULL))
            {
                    RETAILMSG(1, (L" Cam CAM_OV3640_STOP IOCTL failed !!!!\r\n"));
            }
            CloseHandle(m_hDevice);
    }

    }

     

     

    Is there a better way to do the same ... Or is this a complete solution.

     

    Please comment on this.

     

    Thanks

    Misbah

    Friday, December 31, 2010 9:57 AM
  • As i mentioned this a huge module developed my various programmers, finding the location of the crash is difficult.

     

    So i want to try adding a exception handler and stopping the camera inside the handler.

     

    I just know the module which is crashing. Is it possible to put the whole code under __try and __except block ?

     

    and stop the camera under __except()

     

    --Misbah


    Yes its possible, and should be done for every application IMHO.
    All code runs in a thread.
    Write a wrapper-class for a thread, that standard has a try-catch around it's threadfunc.
    When an exception occurs use a callback, to call some global exeption handler function.
    Use this thread-class for ALL threads in your application, forbid direct use of CreateThread() or BeginThread() in the team.

    From what I understand, the problem has nothing to do with the driver-specifics, but mainly with the exeption-catching right ?
    Kind regards,
    Rob
    www.robtso.nl

     

     

     

     

    Monday, January 3, 2011 9:37 AM