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: 

call library function of dll with callback function

Hi, I have a dll file in which there are two DLLEXPORT functions.  However, one is a callback function called by the other function.  The callback function stores an array.  Is it possible to pass this array out into labview by using this dll?

Basically I have a structure like this

 

void DLLEXPORT FrameStreaming()

{

Frame frame;

void StartStreaming();

void Frame_queue(Callback(frame));   //When queue is ready, callback function is called to retrieve the frame by Frame_queue function

}

 

void DLLEXPORT Callback(Frame frame)

{ int array[240][240] = frame.pixelValue;  //pixel value is in the frame whose data type is Frame structure.  

}

 

But if these functions are exported as dll library, in Labview, I don't know how I can get the array out.  Seems in every call library function node, I can only get out what passes into the node as parameters/arguments or the return value of a function.  

 

Is there a way to get around it or am I implementing the dll in a wrong way?  Any guidance is very much appreciated! 

 

Thank you!

 

Best,

Charles

 

0 Kudos
Message 1 of 2
(2,357 Views)

You can allocate a block of memory in LabVIEW using DSNewPtr, and pass a pointer to it to the DLL. You can then copy data from that pointer onto a LabVIEW wire using MoveBlock. If you do that copy periodically in a loop, always copying from the same source location (only call DSNewPtr once), it will likely work. However, it would be better to add some way to know that the callback has been called and has finished copying the data. That way you won't accidentally copy the data before it's completely written. To do this, you may want to start with "How Do I Provide a Callback Function to My DLL Using LabVIEW?"

0 Kudos
Message 2 of 2
(2,343 Views)