From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL and global variables

Solved!
Go to solution

Ok, here's a strange problem.  I'm very new to creating DLLs, so I'm sure I just have a setup problem.

 

But I'm trying to pass a global variable from a host program to its attached DLL.  I had this working when I was on CVI 2014. I recently upgraded to 2015, and then started getting "undefined symbols" errors.  With some wrestling, I got it to compile again, but broke the variable connection in the process.

 

I've compiled my DLL in debug mode so that I step into it from the test project.  Right now, my global variable exists in the test project as well as in the DLL.

 

Do I need to export the variable as well as use DLLEXPORT/DLLIMPORT?  Confused, and oddly not finding anything quite like this on the forums.

 

EDIT: this Stack Overflow post pretty well describes my experience.  I'm statically linking as well.  

0 Kudos
Message 1 of 6
(6,759 Views)

Hi ElectroLund,

 

I see that you are working this same issue with one of our support engineers.  Once there is a solution to this, I think that we should post it here for the rest of the forum users to see.

 

--G-IV

Message 2 of 6
(6,722 Views)

UPDATE

 

Support was unable to help resolve, particularly because this was more of a C programming question, rather than a CVI framework question.

0 Kudos
Message 3 of 6
(6,654 Views)
Solution
Accepted by ElectroLund

Well, what do you know?  I figured out my issue.  This NI article and example project were vital to the solution.  Also helpful was this article called, "Using the Export Qualifier Method".  I'll cut to the chase... 

 

If you use an export qualifier on the definition and an import qualifier on the declaration, LabWindows/CVI exports the symbol.

 

That's the key right there.

 

So in my example, it should look like this:

 

DLL file.c

 

int DLLEXPORT varName = 0;

 

 

DLL header.h

 

int DLLIMPORT varName;

 

Project that uses DLL.c

 

 

#include "DLL header.h"

varName != 1;  // some method of changing this variable in local usage

Pretty easy, huh?  But wow, this took a long time to find.

 

 

 

Message 4 of 6
(6,636 Views)

ElectroLund ha scritto:

But wow, this took a long time to find.


So thank you for describing the solution: it will save time to others who may be in the same situation Smiley Happy



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 6
(6,606 Views)

Hi Electrolund,

 

Here is a pair of tightly related web resources that you may also want to keep in your repertoire when writing DLLs:

 

The Ultimate (DLL) Header File: 

http://www.flounder.com/ultimateheaderfile.htm

 

CodeProject source code for "The Ultimate (DLL) Header File"

http://www.codeproject.com/Articles/812/The-Ultimate-DLL-Header-File

 

Same author for both of these, BTW...

 

JB

--
To whom it may concern: My alias is also my nickname, I've had it since I was a (very) skinny basketball-playing teen. OK, so I've got a 38 inch waist now, but my hometown friends haven't shaken that appellation for me. I trust that you will someday be OK with that alias, as I have been with that nickname.
Message 6 of 6
(6,435 Views)