Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

How can I create a Code Interface Node (CIN) Project in Visual Studio 2005?

Primary Software: LabVIEW Development Systems>>Full Development System
Primary Software Version: 7.1
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:

 I am trying to use C/C++ code in LabView.  How should I configure the project build settings in Visual Studio 2005 to be able to use them in Code Interface Nodes (CIN) in LabView?



Solution:

Currently there is a Creating a CIN Project in Visual Studio .NET 2003 tutorial that describes how to configure Visual Studio .NET 2003 to create a CIN project to write CIN code for use in LabVIEW 7.1. This tutorial however doesn't fully work for Visual Studio 2005. If you follow the steps outlined in that tutorial in Visual Studio 2005, you will initially get linker errors when trying to build. 

If you follow the instructions exactly, you will get a linker error the first time you try to build which says error LNK2001: unresolved external symbol _CINRun.  This linker error occurs because of how C++ does name decorations.  By default, the C++ compiler uses a technique called name mangling which incorporates the function name with its signature (list of arguments) in order to create a unique name.  Thus, you need to force the compiler to avoid name mangling by using the extern “C” syntax after the library declarations as in the following code example:

#include "C:\Program Files\National Instruments\LabVIEW 8.2\cintools\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;
}

 
In addition to the configuration settings described in the Creating a CIN Project in Visual Studio .NET 2003  tutorial, a few more settings will need to be changed in Visual Studio 2005.

C/C++ Project Settings

Detect 64-bit Portability Issues
» NO
Advanced » Calling Convention » __cdecl
and set Compile As » Default.


Manifest Tool Settings


LabVIEW CINs required the manifest be embedded within the DLL which is a step that more or may not be done by the linker.  If you don't embed the manifest, when you tried and load the CIN in LabVIEW, you will receive the This application has failed to start because MSVCR80.dll was not found. Re-installing the application may fix this problem error.

You can easily embed the manifest by setting Input and Output » Embed Manifest  » Yes.

Custom Built Step Settings

Command Line » "$(CINTOOLS_DIR)\lvsbutil" -c  "$(TargetName)" -d "$(OutDir)"

Outputs » $(OutDir)$(TargetName).lsb

When using build macros, make sure that the run-time string created is correct as solution and project hierarchies may be different for different people. In this case you are trying to launch the LabVIEW lvsbutil utility with a given command line string. If that string is incorrect, you will receive an error stating A tool returned an error code from "Performing Custom Build Step". Look at the build log and verify the strings to make sure that it is correct.

Deploying CINs from Visual Studio 2005

When you distribute CINs to a machine without Visual Studio 2005 installed on it, you must make sure to install the needed C/C++ runtime libraries.  To do this, you can simply install the Visual C++ 2005 Redistributable Package. This requirement is not specific to CINs but is required by any application that is built against those libraries.


Related Links:

 

Creating a CIN Project in Visual Studio .NET 2003

What Does the lvsbutil Utility in LabView do?

Visual C++ 2005 Redistributable Package



Attachments:





Report Date: 12/31/2007
Last Updated: 04/10/2008
Document ID: 4GU9I4P9

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit