LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem calling a dll

I am experiencing some odd behavior when I call a dll in my LabVIEW vi. Big pictures is this: I am creating a program in LV which will serve as the user interface for a piece of software written in Matlab. We are exporting the Matlab functions to a dll which will be called repeatedly from my vi. We have overcome the hurdle of speaking with the Matlab dll by creating a set of c dll's which convert mxArray datatypes. This all seems to be working well so far. The problem is that LabVIEW crashes when the Matlab dll is first called if I haven't manually selected the dll in the Configure pane of the Call Library Function node. I have a very simple test vi which I've experimented on. The vi just calls Initialize and Terminate functions from the Matlab dll in a sequence structure. These functions have no inputs or outputs. Here are my observations:
1) start LabVIEW, load vi and run = crash
2) start LabVIEW, configure either Call Library Funtion node and browse for the dll, Okay, Save, Run = no problem, repeated runs work perfectly
3) perform step 2, close vi and reopen (leaving LabVIEW open), run works perfectly
4) repeat step 1 = crash

Since I can't programmatically Configure a Call Library Function node, I can't think of way to make a reliable vi. Any suggestions?

Chris
0 Kudos
Message 1 of 3
(2,715 Views)
So, I solved the problem, but I don't understand it entirely. The problem comes somehow from replacing the dll with one with the same name (occurs frequently with debugging). The work-around is to force LabVIEW to recreate the path the dll by moving the vi to a new directory, and opening (LabVIEW will display the warnings about the dll not being found at X but was found at X, where X is the same path), then save. Exit LabVIEW, move the vi back, and re-open. Again, the warnings, and save again, now the vi can be run without crashing.

Anyone have any insight on this?

Chris
0 Kudos
Message 2 of 3
(2,701 Views)
Well, I must have confused myself with that "solution" because it doesn't really work. As described previously, my top level vi calls two subvi's, one that intializes the matlab dll, and one that terminates it. Here are some further observations:

If the Top Level VI is in the same directory with the matlab dll (and it's 90+ friends) the vi will run without incident. However, I would like to avoid having my top level vi sitting there with all those dlls, so I am experimenting with moving it around.

If the top level vi is in another directory and LabVIEW is launched and the vi run, crash. BUT, if I open LabVIEW, and select browse on a path control and select the directory (or a file in the directory) that contains the dlls, then run, no problem. This is actually what was occurring in my first post, but I didin't realize it. It is not necessary to configure the Call Library Function nodes; all that needs to be done is somehow change the Working Directory to the directory containing the dlls. Unfortunately, I can't figure out how to do this programmatically. I've tried playing with System Exec, but the Working Directory doesn't keep after the call is completed. I've also tried opening a file from the directory, but this doesn't seem to change the WD at all.

Any thoughts or insights would be appreciated. I'd like to know what actually happens behind the scenes when a file/directory is selected from the dialog. This problem seems to be localized to handling dlls generated from Matlab because so many external dlls are required to be called dynamically.

Thanks,
Chris
0 Kudos
Message 3 of 3
(2,631 Views)