View Full Version : Beginner with Unhandled Exception

December 17, 2006, 15:47:32
I'm a beginner at IC Image Control Professional 3.0. I am running an XP Pro box with Visual Studio.net 2003 (Academic). My goal is a standalone windows application that has two functions (a) real-time video preview in a resizable window (scales the image), and (b) pushing a button leaves a bitmap file (e.g., .jpg) in a specified (or default) directory. A counter in the filename of the bitmap file should increment automatically, so that a series of bitmaps will be accumulated. (There should be a button to reset the counter to 0.) (I may add other functionality to the picture-taking button later.)

Under New|Project I selected Visual C++ Projects|IC Imaging Control 3.0 and for Templates I selected IC Dialog Application. Following the wizard I created a directory c:\Trig\ICVC, entered my license key, enabled image processing and display of image and did a build. Fatal errors were corrected by copying the entire set of *.h files into my directory. Then I also had to copy *.lib files, and got a clean compile. Then I did F5 and found that I also needed TIS .dll files, so I got them. Long story short, upon F5 I got an unhandled exception (see attached image). My suspicion is that fooling around with directory structure shot me in the foot. Should I delete everything and uninstall IC Imaging Control Professional and start over, but accept ALL default directory structure?

One fact is that DemoApp.exe works perfectly fine on my box and camcorder. If I could just make some changes to source code for DemoApp.exe according to description above I would be pretty happy. Another fact is that when I try to run DemoApp_vc6.exe from its location in Program Files, there is a failure to find MSVCP60D.DLL.

Stefan Geissler
December 18, 2006, 15:06:41
Hi TimeMachinery,

I have created a small VB.NET sample, that does what you need: simultaneous AVI capture and JPEG image capture. To perform this task a frame filter is necessary, that saves the incoming frames to the image files. AVI capture keeps the same as already shown in the samples.

Please download the two files that are attached to this post. Please unzip the zip file "image_and_avi_capture.zip" into the "samples\vb71" directory of your IC Imaging Control installation path. This path is per default "C:\Program Files\The Imaging Source Europe GmbH\IC Imaging Control 3.0"
The file "SaveImageFrameFilter.zip" must be unzipped to the "Common Files\ICImagingControl3" directory, where the "ICImagingcontrol.ocx" resides.

As I mentioned above, the main task is to insert the frame filter that snaps the images and saves it into an JPEG file. Thus the filter should be declared in the form's class:

' Declaration of the snap image frame filter.
Dim SnapImageFilter As TIS.Imaging.FrameFilter
In the Form1_Load sub the filter is loaded. On success the filter is inserted into the device path of IC Imaging Control:

' Try to load the "Save Image" filter. On success insert this filter in the device path.
SnapImageFilter = IcImagingControl1.FrameFilterCreate("Save Image", "")
If SnapImageFilter Is Nothing Then
MessageBox.Show("Failed to load the Snap Image filter", "Filter Loading", MessageBoxButtons.OK, MessageBoxIcon.Warning)
IcImagingControl1.DeviceFrameFilters.Add(SnapImage Filter)
End If

For snapping of images the button handler that saves the images has to be implemented:

' Snap an image from the live video stream. This can only be done, if the live
' video is running and the SnapImageFilter is not nothing.
' The file name of the image will be advanced with a running number.
Private Sub btnSnapImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSnapImage.Click
With IcImagingControl1
If .DeviceValid = True Then
If .LiveVideoRunning = True Then
If Not SnapImageFilter Is Nothing Then
ImageCounter = ImageCounter + 1
Dim ImageName As String
ImageName = String.Format("Image{0}.jpg", ImageCounter)
' Passing the image name to the SnapImageFilter will snap the image
SnapImageFilter.SetStringParameter("ImageName", ImageName)
End If
End If
End If
End With
End Sub

There is a lot of security stuff in to avoid error messages. The ".SetStringParameter("ImageName", ImageName)" call saves the next image in the stream into the JPEG file.

I suggest to try the sample.

Just another hint: Please use only the .NET ICImagingControl component as shown in the "Components Users Guide". Do not use the ICImagingControl ActiveX directly in Visual Studio .NET.

Please send a request to support@imagingcontrol.com, if you want to have the sample as selfinstalling setup that copies all files to the correct locations.

December 18, 2006, 15:14:16
Thank you Stefan for your instaneous response. I will do as you say and report back.

a.k.a. TimingMachinery

Stefan Geissler
December 18, 2006, 15:34:54
Hi Ellis,

Here is the setup for the sample. This makes the installing processe easier for you.

December 18, 2006, 23:13:00
Hi Stefan,
No problem unzip of "image_and_avi_capture.zip" to specified "...\vb71". However, there is no "ICImagingcontrol.ocx" file on my computer, nor have I found a directory "Common Files\ICImagingControl3" anywhere to put unzip "SaveImageFrameFilter.zip". Also, bad things happen if I just double-click on "image_and_avi_capture_vbnet_setup.exe" in the "image_and_avi_capture_vbnet_setup.zip" file. Please advise, and thanks again.


Stefan Geissler
December 19, 2006, 08:03:57
Hi Ellis,

First off all I guessed that you use Visual Basic .NET and the IC Imaging Control .NET component. Thus I guessed the component is installed. Also I created the sample with Visual Basic.
If you want to use C++ .NET the approach is similar, but the FTF file must be copied to another path.
If you want to try the VB NET sample, then please start the IC Imaging Control setup again and install the .NET components.

I will also create a VC++ 7.1 sample that does the same as VB sample within the next hours. Please excuse my mistake.

Stefan Geissler
December 19, 2006, 12:58:42
Hi Ellis,

I have created the same sample for VC++ 7.1. Since it is not suitable to use the .NET component in C++, the sample uses the IC Imaging Control Classlibrary.
The frame filter is copied into the "classlib\debug","classlib\release" and "bin" directory of you IC Imaging Control installation path. The sample itself will be saved in the directory "snippets\VC.NET\ImageandAVICapture".

You should be able to compile it immediately. Please keep in mind that the DirectShow SDK is needed.

December 19, 2006, 22:34:09
Dear Stefan,

You should be able to compile it immediately. Please keep in mind that the DirectShow SDK is needed.

I got and installed the latest DirectX SDK. Yes, your file compiled immediately (after deleting the error message re license, and putting in my license key) and it definitely takes pictures as required (including video). Excellent.

I do not know how to make the real-time video preview resizable (say, to full screen); nor do I know how to force resolution of image to a fixed value of 720x480 or higher). I am happy to look things up and experiment/debug, but of course in the interest of expedience any further advice would be most gratefully received.


Stefan Geissler
December 20, 2006, 08:13:05
Hi Ellis,

This will be part of the text from the coming code library to this snippet:

Resizing the live video display

The live video should be displayed in a CStatic object named m_cStaticVideoWindow. It should also be resized to the size of m_cStaticVideoWindow. Thus the size of m_cStaticVideoWindow must be queried first by a call to m_cStaticVideoWindow.GetClientRect(&rect). To allow the Grabber to resize the live video display, the property setDefaultWindowPosition must be set to false. Then the width and hight of the previously querried rect are passed to the Grabber's method setWindowSize.

[CRect rect;
m_cStaticVideoWindow.GetClientRect( &rect);
m_cGrabber.setWindowSize(rect.Width(), rect.Height());

I just forgot to say that the CStatic is placed as a text label with the resource editor on the window. Now you know how to resize the live video to any size. You will find this piece of code in the InitLibrary() method of the dialogs cpp.

December 21, 2006, 02:37:27
Hi Stefan -

The attached jpg shows my situation and the code you refer to, I think. I don't quite get how to change code, or some property somewhere, so that if the mouse goes over, say, the lower right hand corner, a resizing arrow appears that allows me to drag the whole window to a desired size.


Stefan Geissler
December 21, 2006, 08:51:36
Hi Ellis,

First of all I would like to show you the correct documentation of the sample I have sent to you. You can see it at:

The application in this sample is a dialog based sample. This means that the window resizing has been disabled. This is a property of the dialog's window and can be changed in the resource editor of Visual Studio. The "Border" property must be changed to "Resizing". Then you should add an event handler for the "Size" event of the dialog's window. (Unfortunately the NCB file is not included in the setup I have provided, thus the size event handler is hard to implement. I will try to fix this.)

In this event handler you can move and resize all of the controls in the dialog window. (SetWindowPos() etc.) This is plain C++ windows programming.
At this point of time i have no matching sample for this tasks.

If you would have used Windows Forms in C# or VB.NET this resizing and moving can be done completely automatic be setting "Anchor" properties for each control.

December 22, 2006, 02:27:14
Hi Stefan,
OK, it seems I have a choice between teaching myself some "plain C++ windows programming" to get a resizable window, maybe with drop down menus instead of buttons to choose parameters/actions, and getting the VB.NET sample to work. So, I executed image_and_avi_capture_vbnet_setup.exe as you provided. When I attempt to compile this I get problems, as shown in the attached image. It seems that I "do not have a license to use this ActiveX control." Please advise, and thank you once again for your help.


Stefan Geissler
December 22, 2006, 08:06:58

The license problem can be solved by removing the IC Control from the form and inserting it again.

If you want to create an application with pull down menus and a toolbar, then I suggest to enhance Demo application. In this application you need only the retrieve the size of the client rect and pass it to the size of IC Imaging Control.
Then the part for the frame filter to snap images must be implemented.

If I remember correctly, I must have a matching sample somewhere. Please give me some time to search for it....

Stefan Geissler
December 22, 2006, 09:49:30

If you would like to enhance the DemoApp, then you would need to add a WM_SIZE message handler to your application for the CMainframe [class. The hander methods looks as follows:

void CMainFrame::OnSize(UINT nType, int cx, int cy)
CFrameWnd::OnSize(nType, cx, cy);

In the constructor of CMainframe add followig lines:

m_iImageCounter = 0;

m_pSaveImageFilter = FilterLoader::createFilter( "Save Image" );
// Insert the frame filter in the display path.
m_Grabber.setDisplayFrameFilters(m_pSaveImageFilte r.get());


In the class of CMainframe add following member:

smart_com<DShowLib::IFrameFilter> m_pSaveImageFilter;

Then change the OnFileSaveimage method:

void CMainFrame::OnFileSaveimage()
if( m_Grabber.isLive() )
Error e = m_pSink->snapImages( 1, 2000 );
if ( e.isError() )
AfxMessageBox( e.toString().c_str() );

if( m_pSaveImageFilter != NULL && m_Grabber.isDevValid() && m_Grabber.isLive())
char szImageFileName[MAX_PATH+1];

// Setting the parameter "ImageName" of the filter causes the filter to
// snap the next incoming image and save it to a file.

Adding the support for AVI capture is not that simple, because you should create a matching dialog or matching controls in the toolbars. You can use the functionality I have shown in the sample I have sent to you. Documentation of the sample is here: http://beta.imagingcontrol.com/library/cpp/section/video-aquisition/example/image-and-avi-capture/

December 24, 2006, 15:14:54
Hi Stefan,

I have added OnSize as suggested, please see attached OnSize.jpg. It does not work yet, please see attached NotResized.jpg. Thank you for your help, and best wishes for the holidays.


ADDED DECEMBER 26: I have moved on to working with the ScrollAndZoom example in Visual C++ (your vc71 sub-directory). The zoom of 140% works very well for me, so I don't have to insist on resizing, as above. I do believe I can bring in the ability to add a counter to saved .jpg's, so that is probably not a problem either. What I am having fun with right now is renaming the entire project. In other words, I copied all the source files for ScrollAndZoom to a separate directory, and am trying to rename everything in site (filenames, and inside of source and header files) from ScrollAndZoom to T_Rig. I will also be creating my own icon. This is not exactly a cake walk.

ADDED DECEMBER 28: I moved the source and resource files to my own directory, T_Rig. I replaced every occurrence of "ScrollandZoom" inside every file by "T_Rig". I found the right paths for include and library files, and LO, the application compiles and links to produce an executable. It seems to require 3 DLL's in the same directory as the executable to run. It does work. What I need to do now is learn how to number consecutive jpgs, so I am studying the code for the snippet you provided, ImageandAVICapture, thank you. I have also been editing the icon, T_Rig.ico, but that is not affecting the icon that shows up in Windows Explorer, which still shows the IC icon.


Johannes Vogel
December 29, 2006, 08:47:11
Hello Ellis,

I think you are suffering from a caching problem. The explorer chaches the icons and does not bother to update the database if the icon changes. I am not a 100% sure about this, but I remember a similar case. Unfortunately, I do not know how to update the cache at the moment.

December 30, 2006, 17:30:02
Johannes -

Thank you for your reply.


Stefan Geissler
January 2, 2007, 11:17:11
Hi Ellis,

For renaming C++ projects is a tool available at
It works for all Visual Studio versions.

The easiest way to change the application's icon is to overwrite the .ico file in the "res" directory with you icon.

March 4, 2007, 15:52:26
When I debug image_and_avi_capture I can't see any of my device? What I have to do?

Stefan Geissler
March 5, 2007, 08:14:05

This is a very good question. What do you mean with it? Are no video capture devices listed in the device list?

March 5, 2007, 09:05:07
Affirmative,no video devices listed in the device list

Stefan Geissler
March 5, 2007, 13:07:40
Hi Toan,

As I wrote in my e-mail to you, I would like to know, which IC Version and License (Pro, Trial, TIS (standard) ) you use and what video capture device you use.

Thank you in advance.