From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calling a dll function that as a structure

I'm trying to call the following function with the Call library function node:

XLstatus

xlLinSetChannelParams (

XLportHandle portHandle,

XLaccess accessMask,

XLlinStatPar statPar)

The statPar parameter is a stucture which is define as follow

typedef struct {

unsigned int LINMode

int baud rate;

unsigned int LINVersion;

unsigned int reserved;

}

XLlinStatPar;

I used a cluster to pass the data to the function but labview is crashing everytime. The  C output of the CLFN is :

typedef struct {
 unsigned long LinMode;
 long baudrate;
 unsigned long Linversion;
 unsigned long reserved;
 } TD1;

long _xlLinSetChannelParams28(long portHandle, uInt64 accessMask,
 TD1 *statPar);

Why is labview sending a pointer to the struct instead of the structure itself? Is this the cause of my problem? Any Solution?

0 Kudos
Message 1 of 5
(2,582 Views)

If I'm understanding this correctly (and note, I'm not a C programmer and I don't have that much experience with CLFNs), then the pointer is to the area LV allocates in memory for the CLFN to place the data into.

I'm not sure what the type conversion should be, but if it doesn't match and you use a pointer, then I see how this could be a problem.

I suggest that you start by checking if the parameter is set to handle by value or by pointer and make sure it's by value.

After that, I would look at the example which shows how to call various C types and which is referenced in the help for the CLFN and maybe also read the other paper that's referenced there.

If those didn't help, then I suggest posting the VI and the DLL (and maybe the code for the DLL as well), so that we can play with it.


___________________
Try to take over the world!
0 Kudos
Message 2 of 5
(2,573 Views)
The CLFN ouput shown in my previous message was done with the "handle to value" parameter. As you stated, it sends a reference to the struct memory location.The problem is that i need to pass the structure value as an input and not a pointer to it (well, that's what i think the problem is). I read the various documents about CLFN and I tried the examples but they are all have function of that kind:
 
returnval ExampleFunc (structPointer *struct)
 
While the function in my dll is made like that
 
returnval ExampleFunc (structValue struct) (see the real function in my first message)
 
I included the dll and Vi and documentation for the xlLinSetChannelParams function.  The CLFN node that calls it is the fourth one (the one with a cluster as input). The first 3 CLFN are used to call the initialization function:init driver,get channel and open port.
 
 
 
 
0 Kudos
Message 3 of 5
(2,557 Views)
I can't look at your code and (as I said) I'm not a C programmer, but I don't think you can do this in LV without creating another DLL which will call the function and return the data using a pointer.

___________________
Try to take over the world!
0 Kudos
Message 4 of 5
(2,552 Views)
Since your structure is pretty simple, just numerics, you should easily be able to pass it to and from a DLL.  Here is how to setup the Call Library Function node for the structure input/output.
 
Calling Convention = stdcall (WINAPI).  If the program crashes, try changing this to C.
Parameter = <name of your structure>
Type = Adapt to Type
Data Format = Pointers to Handles
 
You must use pointers so that the DLL can manipulate the data area directly, and not just a copy of the data structure.
You must also be sure that the DLL data types match the Labview types.  Unsigned Int is a U16 in Labview.  Signed Int is I16.  Unsigned Long is U32, and so on.  Usually pointers and handles are U32.
 
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 5
(2,549 Views)