Creating a CIN Project in Visual Studio .NET 2003
Overview
This document describes how to configure Microsoft Visual Studio .NET 2003 to create a Code Interface Node (CIN) project to write CIN code for use in LabVIEW 7.1.
Note: This document assumes that you have Microsoft Visual Studio .NET 2003 and LabVIEW 7.1 installed on a Windows XP machine.
Table of Contents
Creating an Environment Variable
For more information about CINs in LabVIEW 7.1 or earlier, refer to the Using External Code in LabVIEW manual (linked below). In LabVIEW 8.0 or later, refer to the Fundamentals»Calling Code Written in Text-Based Programming Languages book in the LabVIEW Help (linked below) for more information.
You can maintain CIN projects by creating an environment variable that points to the cintools directory of LabVIEW. Complete the following steps to create an environment variable.
- In the System control panel accessory, click the Advanced tab.
- Click the Environment Variables button.
- In the User variables section, click the New button to create a new user-level environment variable.
- In the Variable name text box, type CINTOOLS_DIR.
- In the Variable value text box, type the absolute path to the cintools directory of LabVIEW.

Creating an MFC DLL
Complete the following steps to create an MFC DLL.
- Launch Visual Studio .NET.
- Click the New Project button to display the New Project dialog box.
- Double-click the MFC DLL icon in the Templates section to display the MFC DLL wizard.

[+] Enlarge Image
- Click the Application Settings link.
- In the DLL type section, click the MFC extension DLL button.

[+] Enlarge Image
- Click the Finish button to create the project.
Creating a CPP File
- Click the Solution Explorer tab to display the Solution Explorer tree.
- Delete all items highighted by the red box below. You can delete corresponding files safely from disk after you delete them from the project and save the project.
Using LabVIEW to Create Starting Code for the CPP File
- Launch LabVIEW.
- Click the Blank VI link to create a new, blank VI.
- Place a Code Interface Node on the block diagram.
- Grow the Code Interface Node so it contains three terminals.
- Wire two numeric controls and one numeric indicator to the Code Interface Node, as shown below.

- Right-click the last terminal and select Output Only from the shortcut menu.
- Save the VI.
- Right click the Code Interface Node and select Create .c File from the shortcut menu. LabVIEW creates a .c file that you can use as a starting point for writing code for the Code Interface Node that you configured.
- Replace the content of the SampleCIN.cpp file with the content of the .c file that the Code Interface Node generated.
- Replace #include "extcode.h" with #include <extcode.h>.
- Enclose the function declaration with extern "C" so you can compile the C code in a .cpp file. The .cpp file should be similar to the code below.
/* CIN Source file*/
#include <extcode.h>
extern "C"{
MgErr CINRun(int32 *Num1, int32 *Num2, int32 *Sum);
}
MgErr CINRun(int32 *Num1, int32 *Num2, int32 *Sum){
*Sum = *Num1 + *Num2;
return noErr;
} - Save and close the VI.
Configuring Visual Studio Project Properties
- In Visual Studio, select Project»Properties to display the Property Pages dialog box.
- On the General page, verify that Use of MFC is set to Use Standard Windows Libraries.

[+] Enlarge Image
- Change the configuration items as shown in the screenshots below. The entries that change are shown in bold text, except as noted.

[+] Enlarge Image

[+] Enlarge Image
- On the C/C++»Precompiled Header page, delete the content of the Create/Use PCH Through File and Create/Use Precompiled Header File fields.

[+] Enlarge Image
- Continue changing the configuration items as shown in the screenshots below.

[+] Enlarge Image

[+] Enlarge Image
- On the Linker»Input page, type cin.obj labview.lib lvsb.lib in the Additional Dependencies field.

[+] Enlarge Image
- On the Custom Build Step»General page, type "$(CINTOOLS_DIR)\lvsbutil" "$(TargetName)" -d "$(ProjectDir)$(OutDir)" in the Command Line field and type $(OutDir)$(TargetName).lsb in the Outputs field.

[+] Enlarge ImageConfiguring Visual Studio Project Properties for Release
- In the Property Pages dialog box, select Release from the Configuration pull-down menu.
- Repeat the steps in the Configuring Visual Studio Project Properties section.

[+] Enlarge Image
- Click the OK button.
Loading an LSB File
- In Visual Studio, select Build»Rebuild Solution to create the .lsb file.
- In LabVIEW, open the VI you created in the Using LabVIEW to Create Starting Code section.
- Right-click on the Code Interface Node and select Load Code Resource from the shortcut menu.
- Select the .lsb file you created.
- Run the VI.
Related Links:
Manuals: Using External Code in LabVIEW
Calling Code Written in Text-Based Programming Languages
Reader Comments | Submit a comment »
Worked in Visual C++ Express Edition 2008 (Part 2)
Continue other comment:
3. Under Linker->General "Output File",
the
setting "$(OutDir)\$(ProjectName).dll" as
is
default seems more appropriate than the
proposed change made in this
document.
One last thing: as many settings need to
be
changed in order to get the code
compile and
usable for a CIN, it would be nice to
include
a few steps on how to export these
settings
and import them into future projects. I'm
still trying to figure that one out, as I
will be using this method quite a bit on a
current project that I am working on.
- Nic Linley, Wendell Hull & Associates. nic@wendellhull.com - Sep 23, 2008
Worked in Visual C++ Express Edition 2008 (Part 1)
Hi!
I was able to get this example to work using
Visual C++ 2008 Express Edition. Very much
appreciated! Visual C++ Express Edition may
be a good utility to some LabVIEW developers
who need to work with simple external code
written in C but do not want to pay for the
licensing of the full Visual Studio Suite,
such as myself.
I'm a novice C programmer, and actually know
very little about C++. Here are some notes
that may help other readers:
1. The Express Edition does not allow the use
of "MFC." I am not 100% sure what MFC would
provide to a LabVIEW developer. From "New
Project" I was able to select "Win32 Console
Application" and in subsequent windows of the
Wizard select "DLL" and then "Empty Project".
That seemed to work just fine for me.
2. The settings specified for "Custom Build
Step" in step 7 don't work for VC++ Express
Edition 2008. The "Command Line" setting
that worked for me was:
"$(CINTOOLS_DIR)\lvsbutil" "$(TargetName)" -d
"$(OutDir)" -- this was obvious upon
inspecting the BuildLog.htm that was produced
from the first error. The variable $(OutDir)
contains the path $(TargetDir). Therefore,
$(TargetDir) is not redundant and causes a
path error for the lvsbutil command line
utility.
- Nic Linley, Wendell Hull & Associates. nic@wendellhull.com - Aug 18, 2008
CIN Projects in Visual Studio .net
One addition to my previous comments:
It might be helpful to include the following
information in the document:
- When using the C++ compiler, it's
necessary to export CINRun as an undecorated
symbol, by prefixing the declaration for
CINRun with:
extern "C" CINRun...
Also, the CIN manual advises you to add
cin.obj, labview.lib, lvsb.lib, and
lvsbmain.def from the Cintools. The on-line
document specifies the same modules, but
includes them as additional modules. You can
do one of the other, but not both, or you'll
see duplicate definitions (the linker is not
particularly smart).
Hope this helps someone else...
- John Heerema, Andromeda Computer Systems Ltd.. heerema@andromeda.ab.ca - Dec 4, 2005
CIN projects in Visual Studio .net
The document is very clear and explicit.
Unfortunately, it failed to address the
problem I was having, and which caused me to
search for this document:
Even after following the instructions,
_CINRun is still showing as an unresolved
reference.
In fact, after modifying my project to match
this example, I had additional problems
(duplicate definitions for _LVSBHead and
_gLVExtCodeDispatchTable).
Also, the example failed to address
questions an experienced C++ developer would
naturally have, such as:
- why are precompiled headers not supported?
- why pick an MFC dll as your starting point?
- would MFC windows work?
- why no 64 bit portability?
- John Heerema, Andromeda Computer Systems Ltd.. heerema@andromeda.ab.ca - Dec 4, 2005
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
