LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

call dll with allocation array and use it later

I have C/C++ library (dll) for CCD. A C/C++ program makes few steps to make measurement 

1. Allocate memory.

2. Use function to send memory pointer and size

3. start measurement

4. wait when measurement finish

5 use data from allocated memory

 

I tried to make the same in LabVIEW but in step 5 I don't see that data changed.

 

Any help?

0 Kudos
Message 1 of 8
(3,603 Views)

Are you preallocating memory with some specific values, or are you using that allocated memory to store your measurement data?  Additionally, when do you expect this data to be changed?  It seems like your question and the title of this message don't quite match up.  Are you calling a DLL in LabVIEW, or are you trying to replicate the behavior of a DLL purely in LabVIEW code?  

0 Kudos
Message 2 of 8
(3,591 Views)

This horse has been beaten several times already both here in this forum as well as over at lavag.org. It is certainly doable but the exact solution depends a lot on the actual requirements of your DLL. In general LabVIEW allocated arrays are only guaranteed to exist for the duration of the Call Library Node call to which they are passed. If you want to have memory buffers that persist across several Call Library Node calls, you'll have to do your own memory management. The recommendation here is to write a wrapper DLL in C that does as much as possible of this. Alternatingly you can call LabVIEW memory manager functions like DSNewPtr() etc. through the Call Library Node. You can then pass that memory pointer to your first API, wait on the event to indicate the end of filling in data, and then retrieve the data from that pointer, for instance with a call to the LabVIEW manager function MoveBlock(). And of course you'll have to deallocate the pointer yourself with DSDisposePtr() when you are done. No automatic LabVIEW memory management  that holds your hand and makes sure everything is neat and pretty, it's all dirty memory allocation/deallocation by hand here.

 

If you search for MoveBlock, DSNewPtr, DSNewPClr in this forum and at lavag.org, you'll get quite a few hits that are relevant to this topic.

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

Thank you rolfk!!!

That is my case.

 

P.s. Sorry that ate your time. I couldn't imge correct search words. 

0 Kudos
Message 4 of 8
(3,573 Views)

Ops ...

 

LabVIEW can call void * malloc( size_t bytes) or UPtr DSNewPtr(size_t bytes) function to allocate memory

and void free( void *arrayptr) or MgErr DSDisposePtr(void *arrayptr) function to deallocate memory

 

But I don't know how (void *) can be transfer to array in LabVIEW.

It looks I need to write dll ... Am I correct?

0 Kudos
Message 5 of 8
(3,565 Views)

Yeah, I don't see how a return type of void * can transfer data to an array.  It seems lik you may need to perform some modifications for this to work.

0 Kudos
Message 6 of 8
(3,557 Views)

I was wrong.

I try to use another function memcpy or MoveBlock to change pointer to LabVIEW array (or verse way).

It looks it works in small test program but I have still problem in normal program.

 

Actually, example is here http://forums.ni.com/t5/LabVIEW/array-pointer-from-dll/m-p/1217453#M519958 vi's picture from nathand

0 Kudos
Message 7 of 8
(3,552 Views)
0 Kudos
Message 8 of 8
(3,549 Views)