Language - C Windows Visual Studio

From Phidgets Support

Language - C

Windows with Visual Studio

Welcome to using Phidgets with C! By using C, you will have access to the complete Phidget22 API, including events.

Visual Studio is an IDE provided by Microsoft that can be used to develop code in a wide variety of programming languages, including C/C++.

Install Phidget Drivers for Windows

Before getting started with the guides below, ensure you have the following components installed on your machine:

  1. You will need the Phidgets Windows Drivers

Using Phidgets in Your Programs

There are two main ways you can go about adding Phidgets to your programs in Visual Studio. You can either start from a working project provided by the Phidgets code sample generator, or you can add the Phidgets libraries to an existing Visual Studio project.

Select your preferred method below for instructions:


Finding Code Samples

To find the code sample to use for your Phidget, navigate to the Code Samples page and select your device from the drop-down menu.

C sample code.jpg


Once you select your device, the code sample generator will give you a working code sample, and a selection of options to customize it to your needs.

Using the Code Samples

You can download a working Visual Studio project for C directly from the Code Samples page. Simply make your selections, and click the Visual Studio Project button under Downloads.

C Visual Studio Sample Download.jpg


Open the example project and start the example by pressing the Start button:

Csharp visualstudio run.png

Setting up a New Project

When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget C library. To begin:


Create a new Win32 Console application:

C vs newproject.PNG


Select an empty project and finish:

C vs emptyproject.PNG


If you are using a 64-bit machine, select x64, otherwise, keep x86:

C vs configuration.png


Next, add a new item to your source folder:

C vs additem.png


Give the source file a descriptive name and continue:

C vs addsource.PNG


Access the project's properties:

C vs propertie.png


Next, navigate to Configuration Properties -> C/C++ -> General and add the following line to the additional include directories:

  • C:\Program Files\Phidgets\Phidget22


C vs additionalinclude.png


Navigate to Configuration Properties -> Linker -> Input and add the following line to the additional dependencies:

  • C:\Program Files\Phidgets\Phidget22\phidget22.lib


C vs additionadepend.png

Finally, include the Phidget library in your code, and any other header files:

#include <phidget22.h>
C vs finished.PNG


Success! The project now has access to Phidgets.

What's Next?

Now that you have set up Phidgets to work with your programming environment, we recommend you read our guide on Phidget Programming Basics to learn the fundamentals of programming with Phidgets.Next Arrow.png