Using ActiveDcam API at runtime
Top  Previous  Next

Most applications would use ActiveDcam by embedding one or several ActiveX objects into an application form at design time, as described in the previous topics. Sometimes however you may want to use ActiveDcam SDK dynamically at runtime. This can be useful if you want a user of your application to decide if he wants to use IIDC-1394 cameras or if you are creating a dynamic link library that has no GUI. ActiveDcam easily allows you to do it via its COM programming interface.

C/C++

1. Copy ActiveDcam_i.c and ActiveDcam.h files into your project folder and include them into your project.

2. Add the following defines to a mudule which will be using ActiveDcam functions:

#include <comdef.h>  
#include <atlbase.h>  
#include <atlconv.h>  
#include "ActiveDcam.h"  

3. Initialize COM library and instantiate an ActiveDcam object:
 
IActiveDcam *pActiveDcam;  
HRESULT hr = CoInitialize(0);  
if (hr==S_OK)  
{  
hr = CoCreateInstance(CLSID_ActiveDcam, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDcam, (void**) &pActiveDcam);  
}  
 
4. Start using ActiveDcam properties and methods, for example:

hr = pActiveDcam->put_Camera(0); // selecting camera #0  
hr = pActiveDcam->Grab(); // grabbing a frame  
hr = pActiveDcam->SaveImage( OLESTR("frame1.jpg") ); //saving a frame as jpg file  

Refer to DcamConsole and DcamWin sample applications for more details.


VB6

1. Add the ActiveDcam component to the Toolbox as described in Getting started in VB.

2. Declare a global ActiveDcam-type object variable in the beginning of your code:

Dim WithEvents AD As ActiveDcam  

3. Instantiate an ActiveDcam object and assign it to the variable:

Set AD = New ActiveDcam  
 
4. Start using ActiveDcam properties and methods, for example:

CameraList=AD.GetCameraList    'retreiving the list of names of connected cameras  
AD.Camera=0         'selecting camera #0     
AD.SetFeature "GainRaw", 150   'setting Gain value  
AD.Acquire=True         'initiating the acquisition  

5. To add an ActiveDcam event handler to your code, select the AD variable from the Object combo box on top of your code window and then select a desired event from the Procedure box on the right, for example FrameAcquired. The following fragment will be added to your code:

Private Sub AD_FrameAcquired()  
End Sub  

Refer to DcamByRef sample application for more details.

6. When you are done with using the ActiveDcam object, destroy it with the following command:

Set AD = Nothing  

 
VB.NET

1. 1. Right click on your application in the Solution Explorer, select Add Reference...->COM, then select ActiveDcam Control from the list.

2. Declare a global ActiveDcam-type object variable in the beginning of your code:

Dim WithEvents AD As ACTIVEDCAMLib.ActiveDcam  

3. Instantiate an ActiveDcam object and assign it to the variable:

AD = New ACTIVEDCAMLib.ActiveDcam  
 
4. Start using ActiveDcam properties and methods, for example:

Dim CamLst As Object  
Dim i As Integer  
CamLst = AD.GetCameraList      'retreiving camera list  
CamNumber = UBound(CamLst)   'number of connected cameras found

For
i = 0 To
CamNumber      'filling out combo box with the names of cameras

ComboBox1.Items.Add(CamLst(i))
Next
......  
AD.Camera = 0     
AD.Acquire = True  
 
5. To add an ActiveDcam event handler to your code, select the AD variable from the Class Name box on top of your code window and then select a desired event from the Method Name box on the right, for example FrameAcquired. The following fragment will be added to your code:

Private Sub AD_FrameAcquired() Handles AD.FrameAcquired  
End Sub  
 
6. When you are done using the ActiveDcam object, destroy it with the following command:

AD = Nothing  
 
 
C#

1. Right click on your application in the Solution Explorer, select Add Reference.../COM, then select ActiveDcam Control from the list.

2. Declare a global ActiveDcam-type object variable:

ACTIVEDCAMLib.ActiveDcam AD;  

3. Instantiate an ActiveDcam object and assign it to the variable:

AD = new ACTIVEDCAMLib.ActiveDcam();  
 
4. Start using ActiveDcam properties and methods, for example:

AD.Camera = 0  
AD.Acquire=true;      'starting automatic acquisition  
AD.ShowProperties (true, 0);   'displaying buit-in property pages