LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Importing shared variable (DLL) with simple function

So I'm attempting to use a DLL I was givven to do something simple.

 

string input--> DLL --> three string output.

 

The .h file defines the function like so:

 

struct FunctionName {
char str1[5];
char str2[4];
char str3[2];
};

 

It sems that the wizard is having an issue creating the datatype defined as the struct (which consists of three strings of length (5, 4, and 2).  I've read that sometimes you can go thru the wizard again and create a ctl, but when I did this the function wrapper vi dissapeared form the library it creates...

 

I'm by no means a C programmer, and dont really remember much of it from school at all.

 

I'm looking into this here: https://decibel.ni.com/content/docs/DOC-9080  thinking the answer might lie somewhere in the "adapt to type" selection (but this only seems available on the functions input?

 

Thanks for any advice/suggestions

-pat

0 Kudos
Message 1 of 4
(2,894 Views)

You've only shown the definition of a structure, not of a function. Can you provide the prototype for the function that uses that structure? Does the function expect three separate strings as parameters, or a struct containing three character arrays?

 

If the function expects a struct containing three character arrays, each of fixed length, and the parameter is passed by pointer (this would be normal), then yes, you want to configure the parameter as Adapt to Type. You should create a cluster containing three elements, each of which is itself a cluster. The first of those clusters should contain 5 U8 values, the second 4 U8 values, and the third 2 U8 values. That will match the structure in your example. To get those to strings in LabVIEW, use cluster to array, and then byte array to string. You need to pass the empty cluster into the DLL call; the DLL call fills in the cluster and provides the values on the corresponding output. If you're dealing with C strings you should also know whether they include a terminating null, or if they're simply fixed-size character arrays.

 

For more help, please post the entire real header file, and any relevant LabVIEW code.

Message 2 of 4
(2,885 Views)
nathand,

thanks for the quick reply!

the sttrings im referring to are actually a output from the dll. I want to be able to drop the function in labview, pass it a single string, and receive three strings out of it.

Ill post the other info you requested when I get back to the lab.

thanks again!

-pat
0 Kudos
Message 3 of 4
(2,882 Views)

@PatLyons wrote:
the sttrings im referring to are actually a output from the dll. I want to be able to drop the function in labview, pass it a single string, and receive three strings out of it.

You will still need to pass empty clusters (taking the place of strings, since they are fixed-size) into the DLL, and the DLL will fill in the values. That way LabVIEW allocates and maintains control of the memory used to store those clusters/strings.

0 Kudos
Message 4 of 4
(2,879 Views)