LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting an error cluster back from a Labview DLL when calling from CVI

Does anyone have an example of how to get an error cluster back from a Labview DLL? I've looked at the examples for passing clusters (or structures on the CVI side) and for passing strings. However, the error cluster is a different problem, since it is a cluster which contains a handle to a Labview string. Certainly there are some tricky memory allocation issues involved. My approach has been to allocate memory on the CVI side using the DSNewHandle() function, which is in a Labview library. Documentation for Labview memory management is found in the "Using External Code in Labview" manual, chapter 4. I've attached the some simple code that calls a Labview DLL with an error cluster as an input an
d an output.
0 Kudos
Message 1 of 4
(3,462 Views)
I forgot to attach the files. Here they are.
0 Kudos
Message 2 of 4
(3,462 Views)
I didn't really take a good look at your code, but I have attached a simple example that I made that shows how to pass in a structure as an output argument to a LabView created dll function that will fill it with the value of an error cluster. Make sure to actually look at the source vi for the dll to see that I am passing in a CStr, LVBoolean, and int32 to the function and an error cluster is the output.

Now, I know you may eventually ask the question "how do I pass in an error cluster to a LabView dll" and the answer is quite simply to do it just as I have in this example (pass in each of the parameters for cluster separately and then bundle them once inside of LabView).

The reason you don't really want to create a structure in C that is exactly
the same as the structure for an error cluster that LabView would work with as an output of a vi is that you would have to work with an LStrHandle with memory allocated by the LabView memory manager, this can be a very difficult process and the creation of these LabView specific datatypes in other development environments was not intended to be done by the developers when it was designed (Note: Clusters with string values in them will always use LStr as the string type).

In summary LStrs (and handles and pointers to them) were designed for use in LabView and not in C, only use them when passed back from a LabView dll function and not as an input to one. At any rate, the example I have attached here will allow you to see how to do what you have asked.
Message 3 of 4
(3,462 Views)
Thanks, this solves my problem. You are right, I will also want to pass an error cluster in. I will take your advice and pass the parameters separately then bundle them inside Labview to create a CVI error cluster input. Since I'm using the same VI for Labview, I will define an additional error cluster input which will only be used for Labview (not defined as a parameter for the DLL). Then I'll merge the CVI error cluster input with the Labview error cluster input.
0 Kudos
Message 4 of 4
(3,462 Views)