LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing pointers to and from DLLs using Call Library Function Node

Hello,

 

I've been trying to better understand how pointer handling works when writing to and from DLLs using the Call Library Function Node. I made a simple code (attached) that passes an int variable (x) to a DLL and retrieves the pointer address (xPtr). I then pass xPtr into a second DLL that retrives the value again .Finally I rerun the first DLL to retrive the pointer address a second time, expecting the address to remain the same as before.

 

However I was surprised to find that the address has changed. I'm wondering if there is something wrong with the way I've written this code, or if there is something I dont understand about LabView's handling of pointers and their memory addresses when using Call Library? Is LabView making copies that I'm unaware of?

 

EDIT: I want to add that, what I am really trying to do is enable some form of interprocess communication between my DLL and LabView. I have a DLL that updates a value in an internal while loop. I want to externally access the memory address of that value in LabView so I can get updates at each iteration of the internal loop. Is my approach incorrect, e.g. should I instead be trying to use a callback?

 

Any help/advice on either problem would be greatly appreciated, as this has stumped me for a few days now.

 

Thank you,

Alvin Chen

 

Research Engineer

Rutgers University

Department of Biomedical Engineering

 

Download All
0 Kudos
Message 1 of 4
(3,061 Views)

Your final call is allocating a fresh block of memory, so of course it will not have the same address as the block you allocate on the first call. Given the contents of memory address A, there is no way to find address A. After all, there will likely be many addresses that just happen to contain the same value.

 

I would add an 'Update()' function to the dll. This would run one execution of the loop and return the new value of the variable of interest. If you want the dll to control the timing, then a callback is probably the best option.

0 Kudos
Message 2 of 4
(3,048 Views)

If you want every value, look into LV's PostLVUserEvent() function, which allows you to fire events which LV will process (essentially similar to your callback direction).


___________________
Try to take over the world!
0 Kudos
Message 3 of 4
(3,035 Views)

I recommend using the LabVIEW memory manager functions DSNewPtr, MoveBlock, and DSDisposePtr. You can call these functions using Call Library Function Node with the library name set to "LabVIEW". These functions are described in the LabVIEW help, or search for them on this forum. Use DSNewPtr to allocate a pointer to a block of memory. Pass the address of that memory to the DLL. In the LabVIEW program, periodically call MoveBlock to copy the data from that address onto a wire. When the program stops, release the memory using DSDisposePtr. Of course you may not get every value of the internal DLL loop, depending on how fast the LabVIEW code runs relative to the DLL loop.

0 Kudos
Message 4 of 4
(3,016 Views)