LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a pointer to a pointer to an external DLL from labVIEW

I have a DLL written in VC++. It has a function that takes in a pointer to pointer of a unsigned char (unsigned char**) and the function allocates the memory and copies some string to the mamory and returns the starting address of the allocated memory through the passed in pointer to pointer. The main idea was to dynamically allocate the memory based on the requirement within the DLL.
 
But in LabVIEW CIN I am not able to select a datatype of pointer to pointer. I tried the datatype 'Array1DUnsigned char **' but of no use. 
 
If I allocate the memory outside the DLL and pass the address then things are working fine. I am getting the string that I copy to the passed in address in the DLL.
 
Moreover the labVIEW CIN when returns doesn't show the data from the newly allocated memory rather it shows the data from the memory that labVIEW allocated.
 
I wish to know how a pointer to pointer can be passed and got updated from within the DLL using the labVIEW.
 
Thanks.
0 Kudos
Message 1 of 4
(3,525 Views)
I have had the same problem when trying to call some system functions which require pointer to pointers (address of a pointer)  since there is no easy method of pointer dereferencing I was stuck using a wrapper function with a compatible type.  I would also love to know the best way to do this.  Since LV manages the memory like a managed language it becomes very hard to gain access to the actual memory structures of a dll like is easily done in a language like c++. 
 
Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 4
(3,518 Views)


@falkpl wrote:
I have had the same problem when trying to call some system functions which require pointer to pointers (address of a pointer)  since there is no easy method of pointer dereferencing I was stuck using a wrapper function with a compatible type.  I would also love to know the best way to do this.  Since LV manages the memory like a managed language it becomes very hard to gain access to the actual memory structures of a dll like is easily done in a language like c++. 
 
Paul


Basically you treat the pointer as an uInt32, configuring in the CLN a parameter Numeric, type: uInt32, Pointer to Value. Then you need two more things. One to copy some data into or out of this pointer, and second some fucntion to deallocate the pointer once your done, otherwise you create a memory leak. The second one will depend on the memory manager function called by the external library to allocate that pointer and should be documented in the function description. Usually a library will export a specific function for deallocation, since just assuming that malloc and free will work the same both in the library and in the caller is dangerous at least.

The getting at the data is a little tricky but can be done quite easily. To read that pointer you would configure another CLN with following parameters:

Library: LabVIEW
Function Name: MoveBlock
Calling Convention: C
return value: void
1 param: source, uInt32, pass by value, Wire here your returned pointer from the first function
2 param: dest, String, pass as C String Pointer or alternatively you could use Array of uInt8, Pass as Array Pointer for binary data
3 param: len, int32, pass by value, length of the data to copy in bytes

Don't forget to preallocate the passed in string or array to the length you specify as the 3. parameter. This is done the most simple with Initialize Array with a type of uInt8 and the according length and in the case of a string you then convrt that Byte Array to a Sting with the according Byte Array To String node.

Voila

Rolf Kalbermatter


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

Thanks Rolf Kalbermatter

The method that you pointed out is working fine.

This looks like a round about fashion of accessing the memories via LabVIEW.

Thank you.

Vivek

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