LAVA Forums Buy cool LAVA gear Forums RSS Feed

Welcome Guest ( Log In | Register )

> Related links

Visit our LabVIEW Wiki External Code Portal.


Tags
(This content has not been tagged yet)
 
Reply to this topic Start new topic
> calling a function as an input parameter to a function
freddayz
post Jul 1 2008, 09:28 PM
Post #1


I've come back for more.


Member
Posts: 2
Joined: 24-June 08
Member No.: 11839
Using LabVIEW Since:2003
LV:8.5 ,8.2.1 ,8.20
United States Nothing Selected Nothing Selected


Hello to all,

Is there a method to call a function as an input parameter to a function called from a dll?

The reason why I am asking is due to the fact that I am trying to call the following function from a DLL.

RtxConfigPollingMode(unsigned long PollingInterval, void (*RtxServiceDevices)(void));

this function calls the RtxServiceDevices function as an input parameter, how can I do this with LV?



ThanksNAdvance



Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
Ad
post Jul 1 2008, 09:28 PM
Post #















Tags
(This content has not been tagged yet)
Go to the top of the page
Quote Post
Thang Nguyen
post Jul 1 2008, 10:40 PM
Post #2


Very Active
***

Member
Posts: 143
Joined: 6-February 07
From: Des Moines, IA
Member No.: 7703
Using LabVIEW Since:2006
LV:8.5.1 ,8.2.1 ,7.1.1
United States us_iowa Vietnam


QUOTE (freddayz @ Jul 1 2008, 04:28 PM) *
RtxConfigPollingMode(unsigned long PollingInterval, void (*RtxServiceDevices)(void));


You can consider parameters as input terminals. So what wrong with connecting the output result of the RtxServiceDevices)(void) to the terminal of RtxConfigPollingMode() dll function?

This post has been edited by Thang Nguyen: Jul 1 2008, 10:40 PM


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
rolfk
post Jul 2 2008, 06:02 PM
Post #3


<customize this text>
*****

Premium Member
Posts: 1012
Joined: 9-April 04
From: Rotterdam
Member No.: 349
Using LabVIEW Since:1992
LV:8.5.1 ,8.2.1 ,7.1.1
Netherlands Switzerland Nothing Selected


QUOTE (Thang Nguyen @ Jul 1 2008, 05:40 PM) *
You can consider parameters as input terminals. So what wrong with connecting the output result of the RtxServiceDevices)(void) to the terminal of RtxConfigPollingMode() dll function?


I'm afraid you missed the point that this is a function declaration and the parameter in question is a function pointer. And the OP should be advised that this is not possible in LabVIEW (well it is sort of if you create a LabVIEW DLL that exports a function with the right protoype, then LoadLibrary and GetProcAdress that function and pass the resulting pointer as an uInt32 to the Call Library Node that calls this function).

Sort of because there are many caveats to this approach not the least is the difficulty about maintaining the whole thing. Another one is that it will play very badly once the DLL is created and you upgrade to a new LabVIEW version since the LabVIEW DLL VI can only run in the same LabVIEW process if the caller is exactly the same version as the LabVIEW version used to create the DLL. So while it is possible the solution is a nightmare to maintain in the long run.

Instead the OP will have to create a wrapper DLL in C that translates between this callback function and another LabVIEW callback mechanisme such as occurrences or user events.

Good luck.

Rolf Kalbermatter


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
freddayz
post Jul 2 2008, 07:14 PM
Post #4


I've come back for more.


Member
Posts: 2
Joined: 24-June 08
Member No.: 11839
Using LabVIEW Since:2003
LV:8.5 ,8.2.1 ,8.20
United States Nothing Selected Nothing Selected


QUOTE (rolfk @ Jul 2 2008, 11:02 AM) *
I'm afraid you missed the point that this is a function declaration and the parameter in question is a function pointer. And the OP should be advised that this is not possible in LabVIEW.



Thanks alot for your help. I see that the dll will have to be re-written to accomodate LabVIEW

FD


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
Chip Grandits
post Jul 16 2008, 09:15 PM
Post #5


I want a LabVIEW icon under my name!


Member
Posts: 3
Joined: 12-December 06
From: Boulder Colorado
Member No.: 7251
Using LabVIEW Since:1999
LV:8.5.1 ,8.20 ,.
United States us_colorado Nothing Selected


QUOTE (freddayz @ Jul 1 2008, 03:28 PM) *
I am trying to call the following function from a DLL.

RtxConfigPollingMode(unsigned long PollingInterval, void (*RtxServiceDevices)(void));

this function calls the RtxServiceDevices function as an input parameter, how can I do this with LV?

ThanksNAdvance


Another approach that may work is if you know that, when called from the LabVIEW application you are developing, you will always use the same device servicing function, and furthermore that function is known at development time.

It may be possible to write some C wrapper code such as:
CODE

//prototype of device servicing function you know you can use (must actually be defined somewhere!)
void myTrustyDeviceServicer(void);

//shallow wrapper that simply always uses above service routine
myLVRtxConfigPollingMode(unsigned long PollingInterval) {
RtxConfigPollingMode(PollingInterval, myTrustyDeviceServicer);
}


If there are a couple of alternative for which device service function you will need you can expand the above function with a case/switch statement. If the RtxServiceDevices function cannot be known until run time, then you are correct in your conclusion that a re-write of the DLL is in order.

Still I am not sure this approach will work; it really depends a lot on what it is doing. Your task begins to wind away from LabVIEW and into the realm of C programming

-Good Luck,
Chip

--------------------
Analysis and synthesis should be alternated as naturally as breathing in and breathing out. - Goethe



Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

 




Time is now: 2nd December 2008 - 01:29 AM