LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using global variable to establish preconditions in DLL

Solved!
Go to solution

Hi

 

I have quite a simple problem which is I want to have a global variable that holds preconditions for every fucntion exported into a DLL. So, to be more precise, a global variable must be visible among top level independent VIs.  I want to have a global variable modifier (SET) and selector function (GET) in DLL too. 

 

I have tried to use a global variable but I have managed to used them only for subVIs but not independent VIs.

 

Thanks

 

 

0 Kudos
Message 1 of 11
(2,575 Views)
Solution
Accepted by topic author kretinga

So you want a (compiled) dll function to set a global, and then read this global in the other (compiled) dll functions?

 

I think that should work, but there might be preconditions.

 

Whether you load the dll by a diagram path, or by a static path might make a difference.

 

Also, whether the dll is set to run in any thread or not might make a difference. I don't think it should but run in the UI thread is safer to start with.

 

I know for sure that this trick works with a functional global. I don't think there should be a difference, but if a normal global fails, you can easily switch to a functional global.

Message 2 of 11
(2,544 Views)

Hi Webie,

 

The normal global has not worked for me. I have tried FGV and it has not worked for me either. The DLL is loaded dynamically, could that be the cause?

0 Kudos
Message 3 of 11
(2,523 Views)

Sorry, I wasn't able to delete the post. 

 

The FGV method has worked for me. Thanks for the help!

0 Kudos
Message 4 of 11
(2,518 Views)

Weird that a normal global doesn't work...

0 Kudos
Message 5 of 11
(2,491 Views)

could that be that my DLL gets loaded dynamically?

0 Kudos
Message 6 of 11
(2,453 Views)

Depends what you mean when you say it gets loaded dynamically. If you specifiy the library name (and path) in the Call Library Node it is also loaded dynamically (by calling Load Library) but it is loaded when the VI is loaded and only unloaded when the last VI that references this DLL is unloaded.

If you specify the path through a terminal of the Call Library Node then the DLL is loaded when that node is executed the first time and ONLY unloaded when you call that same node with a different (or empty) DLL path (or the VI is unloaded). So from the point of Windows it is always loaded dynamically but from the LabVIEW point it still remains loaded in the process space in most cases (unless you specify the path as diagram parameter to the Call Library Node and change the effective path during runtime).

The whole is made more complicated because a DLL normally only can be mapped once into a process. And the first reference to it loads it into the process space and any additional references to the same DLL name (even if it is in fact pointing to a DLL with the same name but at another path) only increment a usage counter for that DLL. Every unload request decrements that usage counter and the DLL only really gets unloaded when that counter reaches 0.

As always with programming problems, 1000 words of prosa are seldom as helpful in showing what you have done than a simple test program that others can download and look at to determine what you really want to do.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 11
(2,449 Views)

But shouldn't a global and a functional global behave the same? Both should retain their value(s) unless released form memory, and that should happen exactly the same for both?

0 Kudos
Message 8 of 11
(2,439 Views)

It most likely should, but without seeing what the OP has done, everything is mostly guess work. Also considering that he first claimed that the FGV didn't work either, I"m not sure if he ever veryfied that the normal global also would work when treating it the same way as what he did when he got the FGV case working as desired.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 11
(2,434 Views)

@rolfk wrote:

It most likely should, but without seeing what the OP has done, everything is mostly guess work. Also considering that he first claimed that the FGV didn't work either, I"m not sure if he ever veryfied that the normal global also would work when treating it the same way as what he did when he got the FGV case working as desired.


Agreed. Some code would be needed to make a conclusion.

0 Kudos
Message 10 of 11
(2,403 Views)