From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

For LabVIEW,How to pass parameter to WIN API function when it have a callback function as parameter

Solved!
Go to solution

For LabVIEW,I want to use the WIN API function“ BOOL EnumWindows(WNDENUMPROC lpEnumF,unLcPARAM lParam )”,but the parameter "lpEnumF" is an pointer to an application-defined callback function(EnumWindowsProc), how pass the parameter to lpEnumF in LabVIEW?

 

,

0 Kudos
Message 1 of 2
(1,985 Views)
Solution
Accepted by topic author weschen

@weschen wrote:

For LabVIEW,I want to use the WIN API function“ BOOL EnumWindows(WNDENUMPROC lpEnumF,unLcPARAM lParam )”,but the parameter "lpEnumF" is an pointer to an application-defined callback function(EnumWindowsProc), how pass the parameter to lpEnumF in LabVIEW?


You don't! LabVIEW itself has no way to represent a function pointer from user code. Function pointers need to be defined in C code or something similar. There are possibilities to create a DLL from LabVIEW code with the necessary function prototype, load that function pointer yourself by calling LoadLibrary() with a Call Library node and use that pointer, but this is a true nightmare in terms of maintainibility in the long run. Not only do you get a seperate project target for the creation of the DLL, you also need to devise a smart way to communicate between the VI inside the DLL and the rest of your application. And here things can get very complicated. As long as the DLL is created with the exact same LabVIEW version as the rest of your application you can use things like LabVIEW Queues, Events, Notifiers etc. as the DLL is loaded into the same LabVIEW runtime kernel as your main program. As soon as the versions don't match, the DLL runs in its own LabVIEW runtime kernel and all those refnums have absolutely no meaning across LabVIEW runtimes.

 

My recommendation is usually to bite the sour apple and write a DLL in C that you can then call from LabVIEW.

 

Rolf Kalbermatter
My Blog
Message 2 of 2
(1,954 Views)