LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Interface dll function with struct in LabVIEW

Solved!
Go to solution

Hello,

 

I have a function:

 

HPDF_SetInfoDateAttr  (HPDF_Doc pdf, HPDF_InfoType type, HPDF_Date value) 

The problem is in the last input, HPDF_Date value. HPDF_Date is a struct which looks as followed:
typedef  struct  _HPDF_Date {
    HPDF_INT    year;
    HPDF_INT    month;
    HPDF_INT    day;
    HPDF_INT    hour;
    HPDF_INT    minutes;
    HPDF_INT    seconds;
    char        ind;
    HPDF_INT    off_hour;
    HPDF_INT    off_minutes;
} HPDF_Date;

Now I created the following cluster in LabVIEW:
test.png
In the Call Library VI I set the type to "Adapt to type" and tried the dataformats. However none of them worked. Can any one explain to me why the cluster is not accepted by the function? I know the error is there because the error function of the dll says that I input an invalid datetime format.
The datetime format may look like this:
MemberEffective values
year  
month Between 1 and 12.
day Between 1 and 28, 29, 30, or 31. (Depends on the month.)
hour 0 to 23
minutes 0 to 59
seconds 0 to 59
ind Relationship of local time to Universal Time (" ", +, −, or Z).
off_hour If "ind" is not space, 0 to 23 is valid. Otherwise, ignored.
off_minutes If "ind" is not space, 0 to 59 is valid. Otherwise, ignored.

 

0 Kudos
Message 1 of 41
(5,838 Views)

ps. HPDF_INT is just signed int so a 32bit signed integer.

0 Kudos
Message 2 of 41
(5,813 Views)

No one?

 

Well I uploaded a example. Before running you need to set the path right from where it fetches the .dll in the Call Library VI

 

Hope someone can help.

0 Kudos
Message 3 of 41
(5,789 Views)

Do you have the source headers of the DLLs you are using and have you tried using the Import Shared Library function?

 

Also, right click on your Library Node and generate the corresponding c file. Check to see if there are any differences between the c file generated and your headers. In this way, you can go about fixing your clusters to make sure they map to the structs properly.

0 Kudos
Message 4 of 41
(5,777 Views)

Yes I have the source of the dll and I didn't try that function, Import Shared Library, I didn't knew it excisted. I just tried and I need to give a header file... But my dll exists out of multiply of h. files and c. files. How do I know which one to choose?

 

I will gonne try the second part of your answer now.

I'll keep you updated.

0 Kudos
Message 5 of 41
(5,767 Views)

EDITED:  I'm not sure you can pass a struct by value in LabVIEW.

 

Part of the problem is that you've replaced what should be a "char" in the structure with a string.  Try making "ind" a U8 integer instead.  In LabVIEW, you can convert that to a string by running it through build array, then using Byte Array to String.  To go the other direction, do the reverse - use String to Byte Array, then index element 0.  You might be able to use typecast instead.

0 Kudos
Message 6 of 41
(5,759 Views)

Sorry for my slightly confused earlier message; I replied too quickly.  LabVIEW cannot pass a struct to a DLL function by value.  You'll need to write a wrapper function in C that takes a pointer to the appropriate structure, dereferences the pointer, and passes that to the library.

 

My initial comment about the difference between a char and a string still applies.  If you do write a wrapper as suggested above, you'll want the "ind" parameter to be a U8 as I suggested, not a string.  Also, depending on your compiler setting and how the library was compiled, you may need to add padding bytes after the "ind" parameter to align "off hours" and "off minutes" properly.

0 Kudos
Message 7 of 41
(5,745 Views)

Actually LabVIEW can. A struct passed by value is simply pushed element for element onto the stack. So instead of defining a structure to pass as a single parameter to the CLN, you configure the CLN to take one parameter per structure element (and use the right datatype of course).

Rolf Kalbermatter
My Blog
Message 8 of 41
(5,728 Views)

Question Rofl. What do you mean with CLN?

 

And I tried the workaround with a U8 but wasn't succesfull. Furthermore there is really no solution to get this working? I mean this isn't even a very complicated struct.. 😕

0 Kudos
Message 9 of 41
(5,718 Views)

CLN = Call Library Node.

 

U8 is correct so stay with that. But you will have to configure one CLN Parameter per Cluster element.

Rolf Kalbermatter
My Blog
Message 10 of 41
(5,707 Views)