LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing C++ DLLs in LabVIEW

I have figured out how to implement a simple C++ DLL using the "Call Library Function" in Labview.  I have seen some posts saying that LabVIEW cannot interfact with a C++ DLL using objects in a class, only through simple, typical data types...double, int, etc.  Before working with LabVIEW, I had some code doing exactly what I liked, and don't want to change that.
 
What I have is a "SuperClass" that instantiates two instances of a "Subclass"...among other things.  In its simplest form, this is how the super class looks:
 

#ifdef

DLL2_EXPORTS

#define

DLL2_API __declspec(dllexport)

#else

#define

DLL2_API __declspec(dllimport)

#endif

#include "Subclass.h"

class

DLL2_API SuperClass{

public

:

SuperClass(

void);

~SuperClass(

void);

Subclass *AZ;

Subclass *EL;

};

extern

DLL2_API Subclass *ptr1;

extern

DLL2_API Subclass *ptr2;

I can get the superclass to work all by itself until I add the instantiation of the subclass.  The compiler gives me a bunch of unresolved externals that are mostly concerning the subclass.  The Subclass is really simple.  All it has are a bunch of private variables, some set and get functions and some simple calculations.  Most of the functions that I want to be able to use in Labview may be accessing the ptr1 and ptr2 information like so: 

double returnSubclassVariable(index)

{

     return ptr1[index].getSubclassVar();

}

Question 1:  Can LabVIEW make use of this function even though it has Subclass usage? 

Question 2:  What syntax needs to be added to a basic "subclass" definition to make this possible?  Does the subclass have to be its own DLL?  Be mindful, I have never worked with DLLs before today, so try to keep it dumb for me.  If the answers to these questions are too complicated, at least a "yes it's possible"  would give me a glimmer of hope.  Thanks a lot!

 

0 Kudos
Message 1 of 4
(2,568 Views)
This post might help you get started, but it doesn't directly address any issues with subclasses. Where exactly are you getting an error or warning message? On LabVIEW's side? Or are you getting warnings from the C++ compiler? If not, what exactly is happening?
Jarrod S.
National Instruments
0 Kudos
Message 2 of 4
(2,556 Views)

I am very new to DLLs.  It appears that I had not made sure that both of my classes were being compiled.  It seemed to have take care of the errors.  I'm a little worried now after seeing the post you refered me to, because I didn' make a COM dll (I don't think) and I was able to acess my functions in labVIEW.  I didn't use the __stdcall or anything though.  My function headers look something like this:

MYDLL_API functionName()

will this cause me problems for reasons I may be unaware?

I also haven't been able to really test my functions because I have variables in my dll that have yet to be populated.  I want to populate them using another c++ file but I'm getting something wrong.  How do you include/import a dll into a regular old c++ program.  I thought #import "mydll.dll" was what I needed but the error it gave me was

fatal error C1083: Cannot open type library file: 'mydll.dll': Error loading type library/DLL.

0 Kudos
Message 3 of 4
(2,548 Views)
I'm a bit confused by your second question. Are you trying to import this dll into another c++ application? If so, I'm afraid I won't be much help with that.

Regarding the way you declare you function in the c++ file: it is important to declare your function as extern c so that it doesn't get any name mangling by the compiler. LabVIEW won't be able to reference the function properly by name in this case. This KnowledgeBase is an oldie but a goodie for this case.
Jarrod S.
National Instruments
0 Kudos
Message 4 of 4
(2,529 Views)