LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

dll with a complex type in a structure

Hi,
I am using a dll that contained a struct with a complex type such as array.

the issue that I am facing is that when I pass the struct as a adapt to type ad putting the same parameter in it the data that i am getting is not as the accepted. can some on help me please .

thank you,
Georged.

0 Kudos
Message 1 of 16
(1,931 Views)

@gmassaad1 wrote:

Hi,
I am using a dll that contained a struct with a complex type such as array.

the issue that I am facing is that when I pass the struct as a adapt to type ad putting the same parameter in it the data that i am getting is not as the accepted. can some on help me please .

thank you,
Georged.


We need more information that this.

 

A function prototype would help.

 

Also, post what you have.

 

It would help to know how it fails...

 

If I had to guess, the API array is fixed size. So you can probably replace it with the right amount of integer data (e.g. a U8 for each element in the array). A LabVIEW array will always be a pointer.

 

Another option would be that the array size needs to be pre-allocated.

0 Kudos
Message 2 of 16
(1,910 Views)

this is the function that I am using to create the dll

 

APICALL bool STACKMODE test1(connect_t IP ,char IPT1[256], char IPT[256], char *hello) {
for (int i = 0; i < 5; i++) {
IPT[i] = IP.IP[i];
IPT[i + 5] = IPT1[i + 5];
}
*hello = 10;
return true;
}

 

 

gmassaad1_1-1652098600468.png

 

gmassaad1_0-1652098566485.png

the data that I am receiving from the LabVIEW in arg2 is not as expected 

 

 

 

0 Kudos
Message 3 of 16
(1,896 Views)

Chars are U8s, not I32!

 

Also, you must make sure the input arrays are 256 bytes. I can't see if you do.

 

If would still help if you actually post results, not just 'not as expected'.

0 Kudos
Message 4 of 16
(1,889 Views)

sorry I just send for you the wrong pic there is a simplest way of what I am getting
-the size of the arrays are 256

-IP is adapt to type , handle by value

-IPT is u8 array data pointer minimum size 256

gmassaad1_1-1652101694494.png

 

 

 

APICALL bool STACKMODE test1(connect_t IP ,char IPT[256]) {
for (int i = 0; i < 256; i++) {
IPT[i] = IP.IP[i];
}
return true;
}

 

 

and this is the c++ code.

Again thank you for your support I really appreciate it.

 

 

 

0 Kudos
Message 5 of 16
(1,870 Views)

The array in that cluster will be passed as 4 or 8 (32 or 64 bit) bytes of data (the pointer to the data). So you're copying those 4 or 8 bytes, and 252 or 248 bytes of garbage. Well, not garbage, but actual memory. Write to it (often enough), and you will get crashes for sure!

 

In LabVIEW there's no way to pass strings or arrays in clusters any other way. You'll always get a pointer to the data, not the data.

 

You have to somehow convert that data. There are several ways to do this, none are particularly easy though. The solution depends on your goals. It would help if you can redesign the API to better fit LabVIEW.

0 Kudos
Message 6 of 16
(1,854 Views)

This is still useless information. You do not show how the type of connect_t is defined. And whatever it is defined it is NOT/NEVER compatible with a LabVIEW struct that contains an array or string. LabVIEW strings and arrays are so called handles, a pointer to a pointer to the actual data with a prepended i32 for every dimension. Unless the C code was SPECIFICALLY written to interface to such LabVIEW datatypes, it will never ever be a compatible datatype that the C code expects.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 7 of 16
(1,828 Views)

@rolfk wrote:

You do not show how the type of connect_t is defined


connect_t is shown in https://forums.ni.com/t5/LabVIEW/dll-with-a-complex-type-in-a-structure/m-p/4229319/highlight/true#M... to be

struct connect_t { char IP[MLMAXADDRLEN]; };
0 Kudos
Message 8 of 16
(1,788 Views)

Isn't a char[256] made as a 256 element u8 cluster? I have some memory of that being a solution in some old thread.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 9 of 16
(1,777 Views)

@Yamaeda wrote:

Isn't a char[256] made as a 256 element u8 cluster? I have some memory of that being a solution in some old thread.



I also remember that. I recently had an array of char of size 32 inside a struct/cluster I dealt with in this way. It seems incredibly hacky and needlessly difficult to maintain. I guess writing wrapper functions that return LabVIEW-native types would be a cleaner solution. I'd enjoy hearing other solutions though.

0 Kudos
Message 10 of 16
(1,767 Views)