The 25 days of C++mas - December 8 - A/V Capture Devices and Sensors

Posted by on in Blogs
C++Builder XE3 includes classes for identifying, managing and using the audio and video capture devices that are available on your target Windows and Mac computers. Classes are also provided for identifying, managing and using any sensors that are available on your target Windows and Mac computers. In this blog post I show you how to use C++Builder XE3 and FireMonkey 2 (FM2) to list all of the A/V capture devices and sensors that are available on a computer.

On my MacBook Pro, the code will find several audio devices, and the built-in camera:

On my Samsung Slate series 7 running Windows 8 Professional, the following is the output from the program showing several A/V capture devices and several sensors:

As you can see from the application displays above, the main form contains two TButton, two TLabel and two TMemo components. The C++ code for the project's button onClick event handler(s) source code is:

#pragma hdrstop

#include "MainUnit.h"
#include "FMX.Media.hpp"
#include "System.Sensors.hpp"
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm4 *Form4;
__fastcall TForm4::TForm4(TComponent* Owner)
: TForm(Owner)
void __fastcall TForm4::Button1Click(TObject *Sender)
// get list of found devices - if any
int NumberOfDevices = TCaptureDeviceManager::Current->Count;
Label1->Text = "Devices: "+IntToStr(NumberOfDevices);
for (int i = 0; i < NumberOfDevices; i++) {
+ ": "
+ TCaptureDeviceManager::Current->Devices[i]->Name
+ ". MediaType: "
+ System::Typinfo::GetEnumName(
+ ". State: "
+ System::Typinfo::GetEnumName(
void __fastcall TForm4::Button2Click(TObject *Sender)
// get list of found sensors - if any
TSensorManager::Current->Active = true;
int NumberOfSensors = TSensorManager::Current->Count;
Label2->Text = "Sensors: "+IntToStr(NumberOfSensors);
for (int i = 0; i < NumberOfSensors;i++) {
+ ": "
+ TSensorManager::Current->Sensors[i]->Name
+ ". Category: "
+ System::Typinfo::GetEnumName(
+ ". State: "
+ System::Typinfo::GetEnumName(
TSensorManager::Current->Active = false;

Additional information about how to use Delphi RTTI type information, "GetEnumName", in your C++Builder applications is available at

Additional information about the TCaptureDeviceManager and TSensorManager classes is available on the Embarcadero DocWiki at

Sensor Categories and Types

Sensor APIs (TSensorCategory) supported by C++Builder XE3 include:

  • Location

  • Environmental

  • Motion

  • Orientation

  • Electrical

  • Mechanical

  • Biometric

  • Light

  • Scanner

For each sensor category, the following are the possible sensor types defined in the System.Sensors.hpp file:

  • enum class TLocationSensorType : unsigned char { GPS, Static, Lookup, Triangulation, Broadcast, DeadReckoning, Other };

  • enum class TEnvironmentalSensorType : unsigned char { Temperature, AtmosphericPressure, Humidity, WindSpeed, WindDirection };

  • enum class TMotionSensorType : unsigned char { Accelerometer1D, Accelerometer2D, Accelerometer3D, MotionDetector, Gyrometer1D, Gyrometer2D, Gyrometer3D, Speedometer };

  • enum class TOrientationSensorType : unsigned char { Compass1D, Compass2D, Compass3D, Inclinometer1D, Inclinometer2D, Inclinometer3D, Distance1D, Distance2D, Distance3D };

  • enum class TElectricalSensorType : unsigned char { Voltage, Current, Capacitance, Resistance, Inductance, ElectricalPower, Potentiometer };

  • enum class TMechanicalSensorType : unsigned char { BooleanSwitch, BooleanSwitchArray, MultiValueSwitch, Force, Scale, Pressure, Strain };

  • enum class TBiometricSensorType : unsigned char { HumanPresence, HumanProximity, Touch };

  • enum class TLightSensorType : unsigned char { AmbientLight };

  • enum class TScannerSensorType : unsigned char { RFID, Barcode };

If you don't have a GPS connected or built-in to your Windows computer, you can download the free "Geosense for Windows" location driver (available for 32-bit and 64-bit Windows) at Mac OS X has built in Location support. You need to make sure and turn location support on in System Preferences -> Security&Privacy -> Privacy tab – make sure “Enable Location Services” is checked. On both Windows and Mac you can see lists of applications that are using location services. On Mac the apps are displayed on the same Privact tab. On Windows you can see the applications use of Location service in the Event Viewer. The first time (or anytime) your application tries to use the Location Service, you will be asked if it is okay for that application continue to run.

CodeRage 7 C++ Conference, December 10-12, 2012

The CodeRage 7 C++ conference starts next Monday, December 10, 2012 at 6am Pacific Standard Time (14:00 UTC).  There are 3 days of C++ sessions including my special live, online conversation with Bjarne Stroustrup at 8am PST (16:00 UTC) on Monday.  Some of the C++ sessions you won’t want to miss are included in my blog post on November 21 -

Happy C++mas!

During the first 25 days of December leading up to Christmas, I will blog about the upcoming release of the C++Builder 64-bit compiler for Microsoft Windows and C++Builder XE3 support for building VCL and FireMonkey 2 applications.

Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.


Check out more tips and tricks in this development video: