void CanonCamera::UpdateView()
{

	if(!liveView)
		return;

    EdsError err = EDS_ERR_OK;
    EdsStreamRef stream = NULL;
    EdsEvfImageRef evfImage = NULL;

    // Create memory stream.
    err = EdsCreateMemoryStream(0, &stream);
  
	if(err != EDS_ERR_OK)
    {
        printf("Error in EdsCreateMemoryStream: 0x%X\n", err);
    }    

    err = EdsCreateEvfImageRef(stream, &evfImage);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsCreateEvfImageRef: 0x%X\n", err);  
    }    

	
	bool wait = true;

    int numTries = 0;
    
	while(wait && numTries++ < 20)
    {
        err = EdsDownloadEvfImage(camera, evfImage);
        if(err != EDS_ERR_OK && err != EDS_ERR_OBJECT_NOTREADY)
        {
            printf("Error in EdsDownloadEvfImage: 0x%X\n", err);

        }
        if(err == EDS_ERR_OBJECT_NOTREADY)
        {
            Sleep(250);
        }
        else
        {
            wait = false;
        }
    }
    if(numTries > 20)
    {
        printf("ERROR: camera is taking too long for EdsDownloadEvfImage\n");

    }

    unsigned char* pByteImage = NULL;

    // Get image (JPEG) pointer.
    err = EdsGetPointer(stream, (EdsVoid**)&pByteImage );
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsGetPointer Histogram: 0x%X\n", err);
  
    }

    EdsUInt32 size;
    err = EdsGetLength(stream, &size);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsGetLength Histogram: 0x%X\n", err);
 
    }

    EdsImageRef image = NULL;
    EdsImageInfo imageInfo;

    err = EdsCreateImageRef(stream, &image);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsCreateImageRef: 0x%X\n", err);
 
    }

    err = EdsGetImageInfo(image, kEdsImageSrc_FullView, &imageInfo);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsGetImageInfo: 0x%X\n", err);

    }

    if(imageInfo.componentDepth != 8)
    {
        printf("Error imageInfo.componentDepth != 8\n");

    }

	liveImage = cvCreateImage(cvSize(imageInfo.width, imageInfo.height), IPL_DEPTH_8U, imageInfo.numOfComponents);

    
    EdsUInt32 DataSize = 0;

    CImage cImage;
    HRESULT hr;

    CComPtr<IStream> iStream = NULL;
    HGLOBAL hMem = GlobalAlloc(GHND, size);
    LPVOID pBuff = GlobalLock(hMem);
    memcpy(pBuff, pByteImage, size);
    GlobalUnlock(hMem);
    hr = CreateStreamOnHGlobal(hMem, TRUE, &iStream);

    // Get the bitmap image from the stream
    if ((hr = cImage.Load(iStream)) == S_OK)
    {
        
        int pitch = cImage.GetPitch();
        int height = cImage.GetHeight();
        BYTE* pBits = (BYTE*)cImage.GetBits();
        if (pitch < 0)
            pBits += (pitch *(height -1));
        memcpy(liveImage->imageData, pBits, abs(pitch) * height);
		
    }

	cImage.~CImage();
    
    GlobalFree(hMem);
	

    cvFlip(liveImage, NULL, 0);

    // Release stream
    if(stream != NULL)
    {
        err = EdsRelease(stream);
        if(err != EDS_ERR_OK)
        {
            printf("Error in EdsRelease: 0x%X\n", err);

        }
        stream = NULL;
    }

   
   if(evfImage != NULL)
    {
        err = EdsRelease(evfImage);
        if(err != EDS_ERR_OK)
        {
            printf("Error in EdsRelease: 0x%X\n", err);

        }
        evfImage = NULL;
    }

	EdsRelease(image);
	
	cvShowImage(windowName.c_str(), liveImage);

	cvReleaseImage(&liveImage);
    
}
EdsError EDSCALLBACK CanonEDCamera::handleObjectEvent( EdsObjectEvent event, EdsBaseRef  object, EdsVoid * context) 
{ 
   printf ("Object Event triggered\n");

   CanonEDCamera* mmCanon = (CanonEDCamera*) g_Self;
  
   switch(event) 
   { 
      case kEdsObjectEvent_DirItemRequestTransfer: 
         {
            EdsError err = EDS_ERR_OK;
            EdsStreamRef stream = NULL;

            EdsDirectoryItemInfo dirItemInfo;
            err = EdsGetDirectoryItemInfo(object, &dirItemInfo);

            // do we need to notify the camera?
            /*
             if (err == EDS_ERR_OK)
             {
             CameraEvent e("DownloadStart");
             _model->notifyObservers(&e);
             }
             */

            if (err == EDS_ERR_OK)
            {
               //err = EdsCreateFileStream(dirItemInfo.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
               err = EdsCreateMemoryStream(0, &stream);
            }

            // Set Progress Callback???

            // Download Image
            if (err == EDS_ERR_OK)
            {
               err = EdsDownload(object,  dirItemInfo.size, stream);
            }

            if (err == EDS_ERR_OK)
            {
               err = EdsDownloadComplete(object);
            }

            EdsImageRef imageRef = NULL;

            if (err == EDS_ERR_OK)
            {
               err = EdsCreateImageRef(stream, &imageRef);
            }

            EdsImageInfo imageInfo;

            if (err == EDS_ERR_OK)
            {
               err = EdsGetImageInfo(imageRef, kEdsImageSrc_FullView, &imageInfo);
            }
            if (err == EDS_ERR_OK)
            {
               printf ("Image Width: %d\n", imageInfo.width);
            }


         }
         break; 
        
         default: 
          
         break; 
      } 
    
 
   // Object must be released 
   if(object) 
   { 
      EdsRelease(object); 
   } 
}