04-02-2013 03:25 PM
Hello,
I'm trying to pass a complexed structure to a dll, in the first example LV crash, in second LV report an error
walking thro this FAQ i understand that the problem is with the arrays, struct arrays...
but i have to say i didnt figure out how should i implement the folowing case.
Hope to get support,
Regards,
Dani
04-02-2013 04:27 PM
The most reliable way is to determine what the dll was written in and what format it expects the data. Generally the format of data is quite different in text based languages than how LabVIEW stores the data. One of the most reliable ways is to pass the dll an array of U8 or a string. You need to build this data up from your LabVIEW clusters to the format that the dll expects. For example, in most text based languages a string is defined as an array of characters. It also has a predefined length. Let's say the string is defined as 5 character in length. If your string is "123", in C it would be stored as 0x31, 0x32, 0x33, 0x00, 0x00. In LabVIEW it would be stored as 0x00, 0x00, 0x00, 0x03, 0x31, 0x32, 0x33. As you can see the format is quite different. What you are effectively doing is passing the dll the LabVIEW binary representation of the cluster which does not equal the binary representation of the structure the dll is expecting. You will need to manually convert the cluster to the appropriate binary representation and pass that to the dll.
04-02-2013 04:34 PM
What is the C definition of the structure you want to pass?
If the DLL was not written specifically to work with LabVIEW, then you cannot pass LabVIEW arrays inside of clusters. In C, inside the structure there will either be a fixed-size array, or a pointer if the array size can vary. In the fixed-size case, you need to replace the LabVIEW arrays with clusters that contain the correct number of elements. If the structure contains an array of 12 ints, the LabVIEW cluster needs to contain a nested cluster of 12 I32 elements (you can generate this quickly using Array to Cluster, create a constant from the output).
04-03-2013 03:22 PM
hey nathan,
i understand your sultion and i did give it a try.
i created a cluster of elements in the right order thay should apear in the struct (please dont laugh on me i know its looks a wierd cluster 🙂
but when i try to run it labview crash, cant figure out, any ideas ?
04-03-2013 03:31 PM
Instead of posting incomplete screenshots, can you attach the VI?
Also, what is the C definition of the structure you are trying to pass? What is the prototype for the function in the DLL that you are trying to call? There's no way to tell if you've set up the cluster correctly without that information. You may need to add a few dummy elements to cluster as padding, to make align elements correctly.
You can group elements into smaller clusters inside the larger cluster to make it easier to manage. The data will still be stored in memory the same way.
04-03-2013 04:06 PM
hey please see below the vi and a text file wich i copied from the example VB code, with the structure definition.
i tried to add the vb code example wich is an excel file but i cant upload it.
thanks for your support,
Dani
04-03-2013 04:43 PM
Did the DLL come with any documentation? Do you have a header (.h) file for the DLL, and if so, can you upload it?
If not, where are the definitions of F6X_MAX_INPUTS, F6X_MAX_SOURCES, and F6X_SOURCE_NAME_LENGTH?
A LONG in VisualBasic is 64-bit, so a 32-bit value probably isn't going to work.
I think you want something like the attached control, except using the correct values for the array sizes.
04-03-2013 05:01 PM
Personally I prefer to use a native LabVIEW cluster that contains arrays and more intuitive LabVIEW constructs. I then write a simple coversion VI that will encode/decode the data into the proper binary format. To me this makes the code much more readable and easier to work with and VIs to format that data are not that difficult to create. Here is a basic example of decoding the data returned from a dll. Encoding would work in a similar fashion.
04-03-2013 05:08 PM
Good point. If this were my project my encoding routine would be just a bunch of Array to Cluster and Bundle nodes instead of doing all the string conversions, and I wouldn't ever actually create the control type that I passed to the DLL. But I don't have time to decipher and rewrite the VI that the poster provided, so I was hoping that providing an example of the control would be helpful.
04-04-2013 02:09 PM - edited 04-04-2013 02:15 PM
Hey Nathan,
Pls see bellow atached a word file description that i got from the company.
in the word you can see the full vb code and all the definitions.
tryied to open youe example on my LV 2011 and its stuck (freez).
apreciate your kindly support, hope to get it work!
Dani