Using ActiveGeni API at runtime
Top  Previous  Next

Most applications would use ActiveGeni 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 ActiveGeni SDK dynamically at runtime. This can be useful if you are creating a dynamic link library that has no GUI or if you want a user of your application to be able to allow/disallow the use of GenTL cameras. ActiveGeni easily allows you to do it via its COM programming interface.

C/C++

1. Copy ActiveGeni_i.c and ActiveGeni.h files into your project folder and include them into your project.

2. Add the following defines to a module which will be using ActiveGeni functions:

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

3. Initialize COM library and instantiate an ActiveGeni object:
 
IActiveGeni *pActiveGeni;  
HRESULT hr = CoInitialize(0);  
if (hr==S_OK)  
{  
hr = CoCreateInstance(CLSID_ActiveGeni, NULL, CLSCTX_INPROC_SERVER, IID_IActiveGeni, (void**) &pActiveGeni);  
}  
 
4. Start using ActiveGeni properties and methods, for example:

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

Refer to GcamConsole and GcamWin sample applications for more details.


VB6

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

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

Dim WithEvents AG As ActiveGeni  

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

Set AG = New ActiveGeni  
 
4. Start using ActiveGeni properties and methods, for example:

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

5. To add an ActiveGeni event handler to your code, select the AG 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 AG_FrameAcquired()  
End Sub  

Refer to GcamByRef sample application for more details.

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

Set AG = Nothing  

 
VB.NET

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

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

Dim WithEvents AG As ActiveGeniLib.ActiveGeni  

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

AG = New ActiveGeniLib.ActiveGeni  
 
4. Start using ActiveGeni properties and methods, for example:

Dim CamLst As Object  
Dim i As Integer  
CamLst = AG.GetCameraList      'retrieving 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
......  
AG.Camera = 0     
AG.Acquire = True  
 
5. To add an ActiveGeni event handler to your code, select the AG 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 AG_FrameAcquired() Handles AG.FrameAcquired  
End Sub  
 
6. When you are done using the ActiveGeni object, destroy it with the following command:

AG = Nothing  
 
 
C#

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

2. Declare a global ActiveGeni-type object variable:

ActiveGeniLib.ActiveGeni AG;  

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

AG = new ActiveGeniLib.ActiveGeni();  
 
4. Start using ActiveGeni properties and methods, for example:

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