05-09-2022 05:37 AM
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.
05-09-2022 06:50 AM
@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.
05-09-2022 07:18 AM
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;
}
the data that I am receiving from the LabVIEW in arg2 is not as expected
05-09-2022 07:42 AM
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'.
05-09-2022 08:10 AM
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
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.
05-09-2022 09:39 AM
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.
05-09-2022 12:02 PM
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.
05-10-2022 03:21 AM
@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]; };
05-10-2022 05:08 AM
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.
05-10-2022 05:50 AM - edited 05-10-2022 05:53 AM
@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.