LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

When does LabVIEW release a .dll file after Call Library Function call?

I have a VI that utilizes a Call Library Function node that calls a .dll file.  I would like to know when LabVIEW releases the .dll file.  Doe it occur when the VI is closed or when LabVIEW is closed?  Is there anyway that LabVIEW can force the .dll to close.  Here I guess close means to remove the .dll from memory?
0 Kudos
Message 1 of 12
(10,510 Views)

What do you mean under "releases the .dll"?

 

Its quite easy to check. Just prepare code like this:

 

 

Then start dbgview and see when attach / detach happened.

You will see, that Process Attach called when VI (where this dll was used) is opened. Detach called when Front Panel closed. The same with reference: when open VI by reference, then Attach Process called, and when reference closed, then Detach happened.

 

Andrey.

 

Message Edited by Andrey Dmitriev on 02-18-2009 06:32 PM
Message 2 of 12
(10,496 Views)

"epsilon-delta" <x@no.email> wrote in message
news:1234975210354-855675@exchange.ni.com...
> I have a VI that utilizes a Call Library Function node that calls a .dll
file.&nbsp; I would like to know when LabVIEW releases the .dll file.&nbsp;
Doe it occur when the VI is closed or when LabVIEW is closed?

It is released when all instances of the dll are released. So, when there
are no more VI's with the dll in memory.

> Is there anyway that LabVIEW can force the .dll to close.&nbsp; Here I
guess close means to remove the .dll from memory?

Dynamically (with VI server) calling the VI containing the dll would gain
some control over the dll. You can also make use of window api's to load and
release the dll, but it is much more difficult, since you would need to make
a way to call the functions by there pointers.

Regards,

Wiebe.


Message 3 of 12
(10,492 Views)

Wiebe@CARYA wrote:

"epsilon-delta" <x@no.email> wrote in message
news:1234975210354-855675@exchange.ni.com...
> I have a VI that utilizes a Call Library Function node that calls a .dll
file.&nbsp; I would like to know when LabVIEW releases the .dll file.&nbsp;
Doe it occur when the VI is closed or when LabVIEW is closed?

It is released when all instances of the dll are released. So, when there
are no more VI's with the dll in memory.

> Is there anyway that LabVIEW can force the .dll to close.&nbsp; Here I
guess close means to remove the .dll from memory?

Dynamically (with VI server) calling the VI containing the dll would gain
some control over the dll. You can also make use of window api's to load and
release the dll, but it is much more difficult, since you would need to make
a way to call the functions by there pointers.

Regards,

Wiebe.



Using Dynamic VIs to wrap Call Library Nodes is a good solution for this.

 

Another solution would be to use the new feature since about 8.5 to specify a path to the Call Library Node. The DLL will be loaded on first call and remain loaded until you pass in a different DLL path. You can pass in an empty path to cause the DLL to be unloaded. However one single Call Library Node still holding onto the DLL will of course prevent it to be unloaded.

 

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
Message 4 of 12
(10,467 Views)
epsilon,

rolfk has the right idea. There is more information in this KnowledgeBase
Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
0 Kudos
Message 5 of 12
(10,438 Views)

Reviving an old thread to clarify one aspect of unloading the dll.  In the example in the above noted KnowledgeBase article, it indicates to specify the path for the Call Library Function (plus other steps accordingly) 

 

Question is, how would this be specified when you generate the executable and include the dll file in the executable ?

 

I have a dll file that up until now, had always unloaded when I stopped running the top level vi.  Now all of the sudden it stopped unloading and I have to exit out of LabView all together to get the dll out of memory.  Just closing all the vi's does not remove it from memory and so if I stop the vi, close it, reopen it and execute it, I get the dll in use error.

 

This gets a little frustrating when in delopment mode and I have 6 or 12 vi's open and then I have to close LabView and start over just to get the dll unloaded.  The technique in the knowledgebase should resolve this until I make it an executable though I guess that at that point, stopping the application will exit the LabView runtime so maybe not a problem at that point.

 

Thoughts ??

 

Thanks

Doug

"My only wish is that I am capable of learning each and every day until my last breath."
0 Kudos
Message 6 of 12
(8,801 Views)

If you are calling the unload dll vi before the VI exists, the dll should be unload. I would expect this to work whether you are running the VI in the development environment, or as an EXE. You said this used to work. Are you saying, it used to work as an EXE and now it doesnt. Or are you saying, it used to work as a VI in the development environment, now you decided to try it as an EXE and it doesnt work. Also has the dll been modified?

Wan L
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 7 of 12
(8,763 Views)

Upon further debuggin, I discoverd an error that migrated to the original "shutdown" sequence and stopped the native procedure from closing the link to the dll.  After that, it all  seems to be working as it did before.

 

The dll (from Tescom) is very picky and will not go away unless specifically told to do so or the link is severd by closing LabView entirely.

 

At this point, I am back to normal.

 

Thanks...

Doug

"My only wish is that I am capable of learning each and every day until my last breath."
0 Kudos
Message 8 of 12
(8,743 Views)

@dacad wrote:

The dll (from Tescom) is very picky and will not go away unless specifically told to do so or the link is severd by closing LabView entirely.

 


 

From what you described there is nothing special to this DLL in terms of not wanting to unload. This is standard Windows policy for all DLLs. As soon as an application loads a DLL, either explicitedly through a call of LoadLibrary(), which every Call Library Node does once for the affected DLL, or by implicit linking to a DLL by either another DLL or the process executable, that DLL gets mapped into the process space and its refcount is incremented. If the DLL is already loaded only the refcount is incremented.

When the module which implicitedly caused the DLL to be linked to is unloaded, or when FreeLibrary() is called, which the Call LibraryNode does whenever the VI that contains the CLN is unloaded, or when you pass a different name (including an empty path) to the path input, then the refcount is decremented and if it reaches 0 the DLL is unloaded from the process space.

 

If the Call Library Node is not executing because of an "error in" condition it won't do anything in terms of affecting the refcount of the referenced library either.

 

There are some exceptions during process termination, where the whole refcounting is more or less skipped since the entire process goes away anyways and also to prevent some nasty race conditions that Windows would otherwise run into during unloading of the various modules. But this is all Windows kernel interna and only a few people like Mark Russinovich understand enough about those issues to make a really educated comment about what happens during process termination in respect of DLL unloading.

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 12
(8,716 Views)

So I guess in this case it is LabView that is holding on to the DLL even though the vi's are doing the talking.  And if I close the vi's without explicitly closing the link to the DLL, LV still has it tied up and won't let go until LV itself is closed. 

 

Just trying to wrap my feeble brain around this.

 

Thanks

Doug

"My only wish is that I am capable of learning each and every day until my last breath."
0 Kudos
Message 10 of 12
(8,676 Views)