Language - C Windows Visual Studio: Difference between revisions

From Phidgets Support
No edit summary
(Redirected page to Language - C)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Language]]
#REDIRECT [[Language - C]]
{{NoTitle}}
{{Language_-_C_Dev_Environment_Table}}
{|
|style="vertical-align:middle; width: 60%;"|
<font size=6>'''Language - C'''
 
'''Windows with Visual Studio'''</font>
 
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++.
|{{TOC limit|2}}
|}
 
{{Language_-_C_Intro|Windows|Visual Studio}}
 
==Use Our Examples==
One of the best ways to start programming with Phidgets is to use our example code as a guide. In order to run the examples, you will need to download and install [https://www.visualstudio.com/ Microsoft Visual Studio].
 
 
Now that you have Microsoft Visual Studio installed, select an example that will work with your Phidget:
*{{SampleCode|C|C Examples}}
 
 
Open the example project by unzipping the example folder, and opening the <code>ExampleName.sln</code> file in the ExampleName folder.
 
Once the project is open, start the example by pressing the ''Local Windows Debugger'' button:
 
 
[[Image: c_vs_run.png|link=|center]]
 
 
The application will open the Phidget, list basic information about the Phidget, and demonstrate the Phidget's functionality. Here is an example of an Accelerometer channel on a Spatial Phidget:
 
 
[[Image: c_vs_output.PNG|link=|center]]
 
 
===Unresolved External Symbol===
If you try to compile the program and the linker throws a number of errors called <code>unresolved external symbol</code>, then it is likely the project is trying to run using the wrong platform. Select your platform from the drop-down list, as shown in the image below.
 
[[Image:VS_Select_Platform.jpg|link=|center]]
 
{{Edit_the_Examples}}
 
==Editing the Examples==
{{Language_-_C_Editing_The_Examples}}
 
==Write Code==
{{Language_-_C_Write_Code}}
 
==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:
 
[[Image:C_vs_newproject.PNG|link=|center|850px]]
 
 
Select an empty project and finish:
 
[[Image:C_vs_emptyproject.PNG|link=|center]]
 
 
If you are using a 64-bit machine, select x64, otherwise, keep x86:
 
[[Image:C_vs_configuration.png|link=|center|850px]]
 
 
Next, add a new item to your source folder:
 
[[Image:C_vs_additem.png|link=|center|850px]]
 
 
Give the source file a descriptive name and continue:
 
[[Image:C_vs_addsource.PNG|link=|center|850px]]
 
 
Access the project's properties:
 
[[Image:C_vs_propertie.png|link=|center|850px]]
 
 
Next, navigate to Configuration Properties -> C/C++ -> General and add the following line to the additional include directories:
*C:\Program Files\Phidgets\Phidget22
 
 
[[Image:C_vs_additionalinclude.png|link=|center|850px]]
 
 
Navigate to Configuration Properties -> Linker -> Input and add the following line to the additional dependencies:
*C:\Program Files\Phidgets\Phidget22\phidget22.lib
 
 
[[Image:C_vs_additionadepend.png|link=|center|850px]]
 
Finally, include the Phidget library in your code, and any other header files:
 
<syntaxhighlight lang='C'>
#include <phidget22.h>
</syntaxhighlight>
 
[[Image:C_vs_finished.PNG|link=|center|850px]]
 
Success! The project now has access to Phidgets.
 
{{Language_-_C_Further_Reading}}

Latest revision as of 17:01, 15 March 2021

Redirect to: