LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C Function Pointer in Struct

Hi,

I'm developing code to interface with a pci platform via LabVIEW on a RHEL 7.4 machine. I was successfully able to create the.so library file and I'm in the process of writing VIs to control the device using my .so and the call library function node. The part I'm hung up on is the pci_access struct contained in the pci.h include file. The struct contains function pointers, and I'm not sure how to mimic these function pointers in a cluster. So my question is two-fold:

1. How do I include function pointers in my cluster?

2. If including function pointers in a cluster is not feasible, how would I go about creating a wrapper function for LabVIEW to handle this struct?

 

I have attached a file that contains the pci_access struct. Also, I'm doing this development using LabVIEW 2017.

 

Thanks!

Jason

0 Kudos
Message 1 of 6
(2,597 Views)
0 Kudos
Message 2 of 6
(2,549 Views)

Thanks for your reply! I’ve seen that solution before, but it doesn’t address my key question. I’m looking to represent a function pointer, not just a pointer to a common data type.  As an example, in the struct that I’m referencing, there’s an element “void (*warning)(char *msg,...) PCI_PRINTF(1,2)”, which is a pointer to a function. How do I represent this in a cluster? From what I can gather, you need your cluster elements to match up exactly with your struct elements using the appropriate data type, but I’m not sure how to do that when you are dealing with a pointer to a function. Are you suggesting that I treat it like any other pointer?

0 Kudos
Message 3 of 6
(2,541 Views)

Ah ok.

 

A function pointer can only (practically) be obtained from a dll. so, build a dll with the function, then use LoadLibraryA (or FindResource) and GetProcAddressA to get a pointer to a function.

 

That function pointer needs to be a system sized pointer, that you can bundle\cluster and send to a function.

0 Kudos
Message 4 of 6
(2,532 Views)

Ok, I haven’t tried the solution yet, but I didn’t want to leave you hanging without giving an update. Your solution is for a windows dll, but I’m hoping that it will be the same with a Linux “.so” shared library. Currently I’m verifying I have the correct packages on my Linux computer since I ran into some errors while using the “Call Library Node” that seems to point in the direction of a missing header file. I’ll let you know if your approach works by tomorrow I hope.

0 Kudos
Message 5 of 6
(2,505 Views)

Sorry for the long delay, had to handle to some family emergencies that cropped up. So I didn’t truly get to implement your solution because the pci.h structs actual have other parameters that I realize would be difficult to implement in labview. I’ve decided to run with wrapper functions that bypass the need for labview to replicate the actual structs. I’ve finished writing the wrapper functions, I just need to test it all out in labview at this point.

 

Thanks a lot for your help in this. Replicating the pci.h structures turned out to be more challenging then I originally thought.

0 Kudos
Message 6 of 6
(2,467 Views)