03-01-2007 10:45 AM
03-02-2007 06:24 PM
07-22-2010 01:28 AM
I have tried out to check if the loading and unloading of DLL works in LabVIEW. I see that it does, and there are examples in the web for very simple case, like for e.g. when using a single Call Library Function (CLF) node. However, when there are multiple CLFs, things are not as easy as it seems.
Things that you must keep in mind is that the loading of DLL takes place with the first CLF, which also saves a reference to the DLL. Subsequent CLFs must have their path-in connected to the path-out of the previous CLF. This way it works as when unloading, the empty path will also be relayed from the first CLF to the subsequent CLFs.
However, I have tested to check if it works when the CLFs are within the Case structures. I found that it does not. This is because some of the references to the DLLs are still active which are not released when specific true/false case block is executed.
On the event that you can free all the references to the DLL, it gets unloaded, but missing a single reference would mean it would not be unloaded at all.
If anyone knows the way to release all the references to the DLL, it would be great to check if would work for Case structures.
- Ramesh Marikhu
07-22-2010 04:38 PM - edited 07-22-2010 04:39 PM
@marikhu wrote:
On the event that you can free all the references to the DLL, it gets unloaded, but missing a single reference would mean it would not be unloaded at all.
If anyone knows the way to release all the references to the DLL, it would be great to check if would work for Case structures.
- Ramesh Marikhu
There isn't, other than making sure every Call Library Node that has loaded the DLL is also called with an empty path. Windows and most other dynamic library implementations (I knowHP-UNIX used to not do that at least in early versions) maintain a reference count for each DLL which is incremented with every call to LoadLibrary() or equivalent and decremented on FreeLibrary(). The OS only unloads a DLL when its reference count reaches 0.
A Call Library Node calls LoadLibrary() whenever it receives a non empty path on it's input that is not equivalent to the previous path. It calls FreeLibrary() on the previous DLL path when a different or empty path is passed to it.
When the path input to the Call Library Node is not enabled then LoadLibrary() is called for each such CLN on the configured library path when the VI gets loaded and FreeLibrary() when the VI is unloaded.