LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I read/write global variables in a Labwindows dll, when called from Labview?

Hi,
I have written an instrument driver (dll) in Labwindows/CVI which stores critical parameters as global variables.
This is no problem when using the dll in Labwindows.
However, when I use the functions in Labview, it appears that subsequent calls to the functions using "Call Library Function Node" lose the information stored in the global variables.
Is there a way to overcome this problem.
Thanks,
Nick. 
0 Kudos
Message 1 of 3
(3,240 Views)
Nick,

in my opinion, you shouldn't keep critical information in global datastorages within DLLs. This can lead to exactly those issues you are observing. The main issue is created because you can never really tell when the DLL becomes loaded into memory and when it becomes unloaded.
Ok, in C-based languages, you can explicitly load and unload DLLs, so you can work around that loading issue, but that is contraproductive to the idea of DLLs.
In LabVIEW, you can never choose and tell for sure when loading/unloading of DLLs occur. Normally, each DLL used in your project should be loaded into memory when loading the VI containing the CLFN.

If the DLL becomes unloaded, all its memory is freed, so all global data are destroyed. Calling the DLL anew will allocate new memory with (hopefully) defaultvalues in the data-area.
So you should rewrite the DLL to retrieve the global data via parameters instead of holding it locally. Another way could be storing it to a non-volatile part of memory, e.g. something like an *.ini-file....

You maybe want to take a look into this link for some useful infos.

hope this helps,
Norbert B.
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 3
(3,237 Views)

Thanks Norbert,

In retrospect I agree that this is by far the best option.

Nick.

 

0 Kudos
Message 3 of 3
(3,204 Views)