LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

integrating C++ DLLs to labview

Iam having a DLL written in C++,I would like to know how to integrate this C++ DLL to labview.I know that CALL LIBRARY FUNCTION can be used for integrating DLL created in C language.But i dontknow wether the same can be used for integrating C++ DLL to labview.Iam using labview 7.1.
0 Kudos
Message 1 of 4
(2,959 Views)
reddy wrote:

> Iam having a DLL written in C++,I would like to know how to integrate this

C++ DLL to labview.I know that CALL LIBRARY FUNCTION can be used for
integrating

DLL created in C language.But i dontknow wether the same can be used for
integrating C

++ DLL to labview.Iam using labview 7.1.

In principle it can be used too. There are two main hurdles here. First
All C++ compilers want to mangle function names. As such they get
difficult to locate in the DLL export list. You can avoid this by adding
something like


#if defined(__cplusplus) || defined(__cplusplus__)
extern "C" {
#endif

/* Your exported function declarations here */

#if defined(__cplusplus) || defined(__cplusplus__)
}
#endif

around the declaration of your exported functions in the header file.

The second problem might be parameters. As long as you export simple
functions which take standard C parameters you are of course fine.
LabVIEWs Call Library Node can't deal with C++ object references or
object interfaces at all however.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 4
(2,955 Views)
Thank u very much for ur reply, Rolf.I would like to know, is there any easy method to call C++ DLLs to labview.If so,please give me reply
0 Kudos
Message 3 of 4
(2,952 Views)
reddy wrote:
> Thank u very much for ur reply, Rolf.I would like to know, is
> there any easy method to call C++ DLLs to labview. If so,please
> give me reply.

There is no simple answer to this question. It really depends what the
DLL does and what it exports in what way. Function calls itself are
usually simple to call from the Call Library Node. The specifics about
how to do that depend on your functions. If you know some C programming
you really should be able to figure that out quite easily, otherwise it
will be a problem even with an elaborate explanation about all the
gotchas and possible variants there are. Read the Online Manual in the
LabVIEW menu under Help->Search the LabVIEW Bookshelf->Using External
Code in LabVIEW (PDF only). Also there are several knowledge Base
articles on the NI Developer Exchange about the different data types and
how to import them in what way. Remember C++ really is just a OO wrapper
around C and as such C++ code is not necessarily substantial different
in how it can get linked to in binary format.

As long as the C++ DLL is exporting function calls with standard C
datatypes it is in principle the same as normal C function calls. Name
mangling as applied by most C++ compilers is a pain in the ass but not
an impossible hurdle. If you have control of the source of the DLL you
can apply my previous suggestion to avoid name mangling for exported C++
functions. Otherwise you browse to the actual DLL in the Call Library
Node setup dialog and then in the Function Name control you get a drop
down listbox with all exported functions, eventhough their names may
look a little strange with all the ADF&*$%^SDFFHll and such appended to
the actual function name. If the functions start to take C++ object
pointers as parameters you are in a more difficult situation. Sometimes
you can treat those pointers simply as int32 and pass them to other C++
functions in the same way. If however you need to reference for some
reasons methods in that object directly in the calling application (here
LabVIEW) there is no other way then writing wrapper functions in the DLL
or in a separate wrapper DLL, which hide those object pointers from
LabVIEW and do the object method and public variable reference for you
in the C++ code of that wrapper DLL.

If the C++ DLL however implements a DCOM (also often called Active X)
interface you will have to make sure the DLL is registered properly
(this is usually taken care of by an automatic installer for the Active
X DLL) and then you can access its functionality through LabVIEWs Active
X interface Nodes instead.

Without more detailed information as to what specific kind of C++ DLL
you do want to interface to LabVIEW this is really the most detailed
information I can give you.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 4 of 4
(2,945 Views)