Jump to content

calling a function as an input parameter to a function


Recommended Posts

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

Link to comment

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?

Link to comment

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

Link to comment

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 LV

FD

Link to comment
  • 2 weeks later...

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:

//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

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.