Creating a C++ Program in Microsoft Visual Studio 2005


Microsoft Visual Studio 2005 is a sophisticated environment designed for developing complex

Windows applications. A complete “Project” consists of a “source program” (which you write)

and all the linked header, library, and other resource files. We will be using very few of the

features of this environment to run the relatively simple programs in this course, but we will

need to link to external header files and libraries to use the National Instruments programs to

control the PCI-6024E A/D card. Below is a step-by-step description of how to create a Project,

add your C++ source program, and link to external header and library files.

1. Open MS Visual C/C++. On the computers in the “High-Tech Tools and Toys Lab” You

will find this program under the Start button by following the links: Programs>>

Microsoft Visual Studio 2005 >> MS Visual Studio 2005

2. Under the File menu choose New >> Project and then, in the Visual C++ >> Win 32

Project Type, select Win-32 Console Application. Give the project a name

(suggestion “Lab7_xyz” where “xyz” are your initials). Under “Location,” use your

memory stick if possible. Any files stored on the computer are likely to be erased or

corrupted. Click Next, check the box for Empty Application, and press Finish.

3. You will now have created a folder called Lab7_xyz in your personal directory. This is

your “Project Workspace.” If you look in this folder you will find three files

Lab7_xyz.ncb, Lab7_xyz.sln, and Lab7_xyz.suo and a folder

Lab7_xyz. These files and folder contain information about your project.

4. To create a C++ program in your project you have to add a C++ source file to the Project.

From the Project Menu, select Add New Item >> Visual C++ >> C++ File. Give

your source file the same name as your project (“Lab7_xyz”). The Project and

Location will be your Lab7_xyz Project and your Workspace on your memory stick.

Click OK and you will be transferred to a text editor with an open file Lab7_xyz.cpp.

5. Write your C++ source code for your program. After the customary few lines of

comments and before your int main(void) or void main(void) routine, insert

the following:

#include // input/output to console

#include //NI-DAQ routines for the PCI-6024E

Note: You will need to either add the NI-DAQ header directory to your path by using the Tools

>> Options >> Projects and Solutions >> VC++ menu (as described in 8 below) or use the

entire path to nidaq.h:

#include

6. To use the NI functions, you will also need to the library file nidaq32.lib to your

Project. Under the Project menu, choose Add Exiting Item and mouse to the files in

C:\Program Files\National Instruments\NI-DAQ\lib. You will need to specify the default

file type as All Files or else you will see only the .h files. Highlight the nidaq32.lib

library (it may appear as just nidaq32 if Windows suppresses file extensions) and press

OK.

7. Under the Build menu, choose Rebuild All and hope for no compile or link errors. If

OK, choose Debug >> Start Without Debugging and watch the program run.

Debug, debug, debug.

8. If you set a path to C:\Program Files\National Instruments\NI-DAQ\Include, you will not

need to put the entire path for nidaq.h into your #include statement. To do this, go

to the Tools >> Options >> Projects and Solutions >> VC++ Directories menu,

choose “Include Files” in the pull-down box, and then click in the “Directories” area

until you get an open box. Click in the box until you get a gray button with three dots

(). Click on this and you will be able to click to the C:\Program Files\National

Instruments\NI-DAQ\Include directory. This procedure allows the linker to find the

header files in the National Instruments directory and Visual C will remember this setting

henceforth.

9. Some other header files and library files that you might need for some NI-DAQ functions

are:

nidaqcns.h

nidaqerr.h

nidaqex.h

Olderror.h

nidex32.lib

There is also a dynamic link library nidex32.dll that may have to be in a directory

that is in the path MS Visual C++ searches for execution-time libraries. Don’t worry

about any of these files unless you are using a NI-DAQ program that indicates you need

them.

10. When you finish your work for the day, copy your Workspace folder to your memory

stick if it is not already there. Make sure you have a copy of your source file at least. To

restart your program when you come back to the lab, reconnect your memory stick with

your files and Workspace folder. You can then restart MS Visual C++ and, from the File

menu, open the Workspace or the Project and you should be ready to go.

No comments: