02-16-2021
02:12 PM
- last edited on
05-28-2025
04:31 PM
by
Content Cleaner
I have been given a DLL which uses pointers to callback functions. This is new to me. I have no problem calling DLLs using the Call Library Node. But one of the input parameters to this DLL is a pointer to a callback function. So for example, there is a function call startAcquisition which begins data acquisition. And this function is supposed to trigger a callback function (in the caller) whenever a datapoint is available. And I just discovered that LabVIEW does not allow this.
NI's proposed workaround is to create a wrapper DLL which then "calls back" to LabVIEW (e.g. executes a VI or a User Event) ... and this is done using the LabVIEW Manager functions in labviewv.lib.
This workaround sounds daunting to me, because I am not so skilled in C or C++, but I'm going to give it a shot. My questions to you all are:
Thanks!
02-17-2021 04:14 AM
No C code required.
Make a LabVIEW dll that exports a function with the required prototype.
Then, use LoadLibrary and GetProcAddress to get a pointer to the function.
Of course, you should have a mechanism that communicates the callback data that the function receives back to your application. In my experience, a 2nd function in the dll that reads a FGV works well. The callback fills the FGV, the 2nd function reads and clears the FGV.
05-31-2021
03:26 AM
- last edited on
05-28-2025
04:31 PM
by
Content Cleaner
While the use of a LabVIEW DLL that contains a VI that is exported to match the C prototype of the callback function is a possibility, it has several drawbacks such as causing extra hassles when you want to use your library in a different LabVIEW version as you then also should recreate the according DLL. Also the creation of a compatible callback function prototype requires pretty much the same depth of C knowledge than writing the wrapper DLL would.
To answer the original question, anyone looking for examples, should search here and on Google for PostLVUserEvent(). This is the LabVIEW manager function used to generate a user event from C code. Your callback function inside the DLL will generally want to call this function with the correct data that matches the User Event datatype.
06-08-2021 12:28 AM
While I don't know if this would help you, here's some example code (LV 2015) which I wrote when I was playing with this, which shows what Weibe is describing (building the DLL in LV and then getting the function pointer to a function there).
Note that this was quick and dirty code for a test, so it's messy and probably has some pointy edges, but it should show the basic idea.