viSci Posted June 29, 2017 Report Share Posted June 29, 2017 (edited) I have create a LV wrapper for a DLL that crashes LV when the CLN is simply wired in edit mode and saved. I will admit that the DLL prototype requires a rather obese LV cluster which is so large it freezes LV when probed but still I do not see any other way to convey the data. Here is the diagram... LV will crash when I connect the cluster to the 2nd input of the CLN and then Save. The CLN function prototype is... int32_t LDR_GetCsmuDir(uint16_t *DirType, void *Response); The Response parameter is set to 'Adapt to Type', Pointer to Handle. I also tried 'Handles by Value' as it still crashes. Basically I have a cluster of 256 strings each of which is 256 characters, which appears to be too much for LV to handle. Perhaps there is a way to Malloc the data but that is outside my area of knowledge presently. Edited June 29, 2017 by viSci Quote Link to comment
ned Posted June 29, 2017 Report Share Posted June 29, 2017 The line at the bottom isn't a function prototype; I'm not quite sure what it's supposed to be doing. Can you include more of the header file? Data Format should be set to Array Data Pointer. You should never pass a LabVIEW handle to a DLL unless that DLL is specifically written to handle LabVIEW data types. There's no need to take an empty string, convert it to an array, then type cast that to a cluster; bundle in the cluster constant directly. You could also ignore the structure entirely, compute the size of the cluster ((256 + 4) * 256) = 66560 bytes, initialize an array of that size, and pass that instead. Make sure to pass it as an array data pointer. You can then parse out the returned array however you like (accessing specific subsets, or attempting to convert it to the big cluster). Quote Link to comment
viSci Posted June 29, 2017 Author Report Share Posted June 29, 2017 The Typedef on the last line was just meant to indicate that the DLL function takes two parameters, the first is a pointer to a U16 and the second is a pointer to the data structure I am trying to build. I tried as you suggested, to create a large U8 array and pass it in as a pointer to array and adapt to type. It no longer crashes in edit mode and now waits until I run the vi Quote Link to comment
viSci Posted June 29, 2017 Author Report Share Posted June 29, 2017 Ok I realized I did not follow your instructions correctly. After I changed 'Adapt to Type' to 'Array' it ran without crashing. I am getting back an unstructured string but it is a starting point. Thank you Ned, that was a big help! Quote Link to comment
Rolf Kalbermatter Posted June 29, 2017 Report Share Posted June 29, 2017 (edited) You should probably simply pass a Byte array (or string) of 2 + 2 byte padding + 256 * (4 + 256) elements/bytes as array data pointer and then extract the data from that byte array through indexing and Unflatten from String. Edited June 29, 2017 by rolfk Quote Link to comment
viSci Posted July 5, 2017 Author Report Share Posted July 5, 2017 Hi Rolf - That was a very good try but short 2 bytes. After that adjustment it works great, thanks! Quote Link to comment
viSci Posted July 5, 2017 Author Report Share Posted July 5, 2017 Actually that mod did not work. Here is the solution I came up with. I tried passing in the cluster typedef directly into the DLL but it always crashes . Quote Link to comment
Rolf Kalbermatter Posted July 6, 2017 Report Share Posted July 6, 2017 (edited) 16 hours ago, viSci said: Hi Rolf - That was a very good try but short 2 bytes. After that adjustment it works great, thanks! That won't work for sure!! This strange offset of 2 you added inside the loop would indicate that the according C code was not compiled with standard padding. A completely valid possibility although pretty unusual for DLLs that were not specifically compiled for LabVIEW. Instead you should most likely have changed the constant in front of the loop with the value 4 to 2 to get this properly working! Edited July 6, 2017 by rolfk Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.