LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wrapper DLL with callback using LabVIEW Manager functions (labviewv.lib)

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:

 

  1. Can someone point me to some example code to me get started building a wrapper DLL, preferably with callback to LabVIEW?  Honestly, I have no idea how to even create a DLL project in Visual Studio.
  2. I eventually need to create a built executable from the top level LabVIEW code.  Will these "LabVIEW Manager functions" (e.g. labviewv.lib) still be accessible from the LV RTE?

Thanks!

http://www.medicollector.com
0 Kudos
Message 1 of 4
(2,803 Views)

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.

0 Kudos
Message 2 of 4
(2,744 Views)

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.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 4
(2,652 Views)

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.


___________________
Try to take over the world!
Message 4 of 4
(2,628 Views)