f



labview crashing when calling labview-built dll

Hello I need some help with regard to calling a LabVIEW-built DLL in 
LabVIEW.I have created a vi in LabVIEW. I made the DLL for this vi. I 
called this VI as a re-entrant in another vi.This vi(calling DLL) has 
been working fine till yesterday. Since yesterday, it started crashing 
LV.I need some help in this regard.I am attaching the 
screenshots of the Application Builder configuration window, the B.D of the vi 
using DLL and that of the configuration window which pops up when i call the 
DLL.I made a vi which performs FRA. I built its DLL.I have around 10 
inputs. I output 3 one-dimensional arrays, and a string from the DLL.When i 
build the DLL, the builder defines the outputs 'gain', 'phase' and 'frequency' 
as arrays of 8-byte double.When i call this DLL in my vi, the configuration 
window sets them as 'numeric' outputs.Why does this happen? What is the 
solution to this?When i try to set them as 'array' in this configuration 
window, i get a warning that i am trying to change the data types which do not 
match with the data type found in the DLL. Is this the problem with my 
code or with the Application Builder?Now, after i change the 3 output 
datatypes to Arrays, and set their minimum length(i assumed that this value 
means the size of the array ), the vi runs and crashes LV. I am nto sure when it 
crashes, why it crashes. It runs fine at one time. It crashes at another time. I 
am nto sure if these arrays are teh reason why LV crashes. If that is the 
erason, why is it happening only sicne yesterday and not earlier?Also, 
the string output can is a maximum of 412 characters. Will this play a role in 
LV crashing? Kindly someone help me!!I have checked multiple 
times for the data types of the otehr inputs and ouputs. My only doubt is on 
these arrays.I have posted this message <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=219266&amp;query.id=60082#M219266" target="_blank">here</a>, already. Kindly continue the thread there.


LV error 2.jpg:
http://forums.ni.com/attachments/ni/170/326170/1/LV error 2.jpg


LV DLL.jpg:
http://forums.ni.com/attachments/ni/170/326170/2/LV DLL.jpg


LV DLL _when called.jpg:
http://forums.ni.com/attachments/ni/170/326170/3/LV DLL _when called.jpg
0
x9561 (148438)
5/25/2008 12:40:05 PM
comp.lang.labview 35210 articles. 1 followers. vasusachin24 (1) is leader. Post Follow

13 Replies
1629 Views

Similar Articles

[PageSpeed] 55

LabVIEW version used will be helpfull. I myself also have some trouble with crashes when calling a LabVIEW built DLL. I will dig into this first thing monday morning with my collegue. Maybe we find something in our case that could explain your problem.
0
x9561 (148438)
5/25/2008 2:40:05 PM
Thank you sir! I am using LV 8.2.1
0
x9561 (148438)
5/26/2008 3:40:05 AM
I made a vi which performs FRA. I built its DLL.I have around 10 
inputs. I output 3 one-dimensional arrays, and a string from the DLL.When i 
build the DLL, the builder defines the outputs 'gain', 'phase' and 'frequency' 
as arrays of 8-byte double.When i call this DLL in my vi, the configuration 
window sets them as 'numeric' outputs.The problem is actually here but not as you describe it. The DLL node seems to be configured right since you wire an array of doubles to these three parameters. The problme is about memory allocation.Having the parameter configured as Array data pointer means it is a simple C data pointer and not an LabIVEW array handle. This is good if you ever intend to have this DLL called by some other program than LabVIEW since it is rather hard to make other applications deal right with LabVIEW handles.However for C data pointers the caller is responsible to allocate the memory for these parameters. This means that you can't just wire an empty array constant to the input side of these parameters in the Call Library since this points to a memory aray of 0 bytes length. The function then will attempt to write into that memory area and overwrite memory it is not supposed to overwrite.Replace that array constant with an Array Initialize node that creates an array of sufficient length.Rolf Kalbermatter
0
x9561 (148438)
5/26/2008 7:10:05 AM
Thank you very much sir! I shall try it and get back!!
0
x9561 (148438)
5/26/2008 7:10:06 AM
Sir, I tried using a initialize array function in place of array constant, but in vain.LV is still crashing.Also, what is the difference in using an 'initailize' function and an 'array constant'? I am finally getting a 1-D array.The other doubt i had was : why does the 'call library function node' configuration window detect the outputs 'gain','phase' and 'frequency' as numerics and not arrays?
0
x9561 (148438)
5/26/2008 7:10:07 AM
MScap wrote:Sir,I tried using a initialize array function in place of array constant, but in vain.LV is still crashing.Also, what is the difference in using an 'initailize' function and an 'array constant'? I am finally getting a 1-D array.The other doubt i had was : why does the 'call library function node' configuration window detect the outputs 'gain','phase' and 'frequency' as numerics and not arrays?You do need to make sure to initialize the arrays to the length indicated by your len1, len2, len3 parameters that you also pass to the DLL. An array constant contains only as much elements as you explicitedly enter into it (usually 0, which means it points to a memory area of 0 bytes length). Initialize Array will create a memory block that is large enough to contain the number of elements you specify as length parameter.Rolf KalbermatterMessage Edited by rolfk on 05-26-2008  09:08 AM
0
x9561 (148438)
5/26/2008 7:10:08 AM
Thank you sir! I got the point.I made sure that the no.of elements is same as that of len1,len2 and len3. All these three values are same as the input 'no.of steps'. So, I connected them all together.Now, it runs fine when i pass all the inputs. I have a validation process in my code, which gives an 'error message'(as a string) when any input is not valid ( usually out of data range).LV is crashing, now, only if there are any empty inputs passed to it.When i run the vi without passing any values to the controls, its crashing. Also, its crashing when i enter few inputs and leave others empty. Actually, when no data is passed to the vi, the vi must return a string (of max 412 characters) that the values are not valid.I am gettign this string as the output and then LV is crashing. I am not able to find out the reason.Kindly&nbsp; look into this!
0
x9561 (148438)
5/26/2008 7:40:05 AM
MScap wrote:Thank you sir!I got the point.I made sure that the no.of elements is same as that of len1,len2 and len3. All these three values are same as the input 'no.of steps'. So, I connected them all together.Now, it runs fine when i pass all the inputs. I have a validation process in my code, which gives an 'error message'(as a string) when any input is not valid ( usually out of data range).LV is crashing, now, only if there are any empty inputs passed to it.When i run the vi without passing any values to the controls, its crashing. Also, its crashing when i enter few inputs and leave others empty. Actually, when no data is passed to the vi, the vi must return a string (of max 412 characters) that the values are not valid.I am gettign this string as the output and then LV is crashing. I am not able to find out the reason.Kindly&nbsp; look into this!Same issue probably. When you pass a C data pointer (string or array) you need to make sure to allocate the necessary memory for that parameter in the caller (here your LabVIEW diagram). The DLL has no way of allocating that memory and returning it to the caller.For strings I usually do this by intializing an array of u8 of the necessary size and then using a Byte Array To String function convert it into a string before passing it to the Call Library Node. In LabVIEW 8.2 and higher you also can configure in the Call Library Node a minimum size for array and string parameters. LabVIEW will then make sure to allocate the necessary memory before passing the pointer to the DLL. You can either use an explicit number to allocate a fixed size buffer for statically sized parameters or the name of a different parameter that indicates the number of data elements the array should be resized to.Personally since I still work sometimes in pre 8.2 LabVIEW versions I prefer to do the explicit allocation with Initialize Array myself.Rolf Kalbermatter
0
x9561 (148438)
5/26/2008 8:10:06 AM
Sir, I have made sure that the strings are defined with a minimum length. The array size is connected to an other input(no of steps).As i said earlier, the vi runs fine, without crashing, when all the input parameters are passed. If i do not pass even one parameter, i should get an error message (of max 412 characters). I get this error message and then LV crashes.
0
x9561 (148438)
5/26/2008 8:40:04 AM
Looks like we had the same problem with calling a DLL in LV.Mine was related to a string output of the DLL.Initialise you string output with a string of 412 characters and you're fine.Strings can be intialised in the following way:<img src="http://forums.ni.com/attachments/ni/170/326273/1/Initialise%20string.png"> Message Edited by andre.buurman@carya on 05-26-2008  10:58 AM


Initialise string.png:
http://forums.ni.com/attachments/ni/170/326273/1/Initialise string.png
0
x9561 (148438)
5/26/2008 9:10:09 AM
Thank you so so so very much sir!! We had been worrying over this for a week!!As of now its running fine, without crashing!!:smileyhappy:Thanks again!!
0
x9561 (148438)
5/26/2008 10:10:08 AM
MScap wrote:
Sir,

I have made sure that the strings are defined with a minimum length. The array size is connected to an other input(no of steps).


As i said earlier, the vi runs fine, without crashing, when all the input parameters are passed. If i do not pass even one parameter, i should get an error message (of max 412 characters). I get this error message and then LV crashes.

It's extremely hard to understand what you are exactly doing. Not passing parameters seems like a defnitive error to me but I might misunderstand what you are doing.

Showing your code both how it works and how you try it when it doesn't work would definitly help a lot. Putting up the actual VI with an example of what you try to do would be best.



MScap wrote:
 Thank you so so so very much sir!!

We had been worrying over this for a week!!

As of now its running fine, without crashing!!


<img src="../../i/smilies/16x16_smiley-happy.gif" border="0" height="16" width="16">

 Well I see you got it solved. What I told you in my previous post was in fact the same as what Andre told you later on in a different way.Rolf Kalbermatter
Message Edited by rolfk on 05-26-2008  12:32 PM
0
x9561 (148438)
5/26/2008 10:40:06 AM
Well! I will not be able to post the actual code.I tried with empty parameters because, this DLL will be used in VC++ by someone else.i wanted to make sure that, if the user passes empty paramters, by mistake, the function returns an error. That was the reason, i wanted my vi to run with empty paramters and return the error message.!!anyways!!Thank you both of you for spending your time on my problem!!
0
x9561 (148438)
5/26/2008 10:40:07 AM
Reply: