LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

call function from dll with return void*

I use a function from DLL (c++) with return void* as output, but in LV 6.0, output parameters are void, numeric and char ONLY... but never pointer (from memory block).

How can I do to access correctly to my DLL.

Thanks
Francois.
0 Kudos
Message 1 of 15
(6,485 Views)
Hi,

Output values are not nesseccerilly "void, numeric and char ONLY... ". This
is only true for the return value. So if the dll is homemade, you could make
a dummy pointer input, change the input value (to the return pointer) and
use this in LabVIEW. Or you could make a second function, to do this.

If you do want to use the return value you have a (solvable) problem...

A return value from a (c++ / windows) API is, afaik, always a 32 bit number
(returned in EAX...). A pointer is also a 32 bit number. If it is a pointer,
LV has no way of telling what the pointer is pointing to. That's why this is
not possible.

If your pointer is a pointer to a string, no problem. Selecting a number
output will return the pointer value.

If it is something else, you can convert this poi
nter to string as explain
in the post called "How to bundle a String-pointer into a cluster". But this
string will be truncated at \00. Trick is to iterate the function untill the
desired data is returned. You now have a "flattend data string", that can be
converted to the desired LabVIEW data.

Good luck,

Wiebe.


Note: Save your code occasionally! LabVIEW will crash a lot doing this
stuff.


"pdx" wrote in message
news:506500000008000000E03E0000-1012609683000@exchange.ni.com...
> I use a function from DLL (c++) with return void* as output, but in LV
> 6.0, output parameters are void, numeric and char ONLY... but never
> pointer (from memory block).
>
> How can I do to access correctly to my DLL.
>
> Thanks
> Francois.
0 Kudos
Message 2 of 15
(6,484 Views)
Thanks for the answer,

The DDL is not an homemade and not an API DLL
The DLL return a void* pointer corresponding to the begin of a memory block filled with image video.
We need to transfert data in LV 2D Array (we used an homemade DLL with memcpy function c++ ) but the call of our DDL in LV failed.

Rq: our DDL works with transfert data from LV 2D Array to an other LV 2D Array...

Best regards.
Francois
0 Kudos
Message 3 of 15
(6,485 Views)
"pdx" wrote in message
news:506500000005000000F6640000-1012609683000@exchange.ni.com...
> Thanks for the answer,
>
> The DDL is not an homemade and not an API DLL
> The DLL return a void* pointer corresponding to the begin of a memory
> block filled with image video.
> We need to transfert data in LV 2D Array (we used an homemade DLL with
> memcpy function c++ ) but the call of our DDL in LV failed.
(Exactly what went wrong? Crash, empty array, ...)

You shouldn't need to use memcpy.

What I whould try is this;

Build a dll with two inputs a number (A) and a 2d array (B)

Wire the pointer to A (as a number not as a pointer!)
Wire an empty 2d array to the 2d array (use array data pointer, I think)

In the function, you have two inputs, a poin
ter to the org array, and a
pointer to the source array. Now simply swich the two pointers. (I'm not
sure if this is allowed in c++?.)

The output array should be a 2d array containing the data (copied by
LabVIEW).


I haven't worked with c++, I usually use Masm32 for external functions...

Regards,

Wiebe.

> Rq: our DDL works with transfert data from LV 2D Array to an other LV
> 2D Array...
>
> Best regards.
> Francois
0 Kudos
Message 4 of 15
(6,485 Views)

Hello Francois,

I have the same issue with my device, were you able to get the 2D array from your camera with void*? If so, could you please send an example of how you were able to do it?

 

Thanks,

Omer

0 Kudos
Message 5 of 15
(6,066 Views)
Hi Omer,

Can you describe more of what exactly you are experiencing for us to better assist you.
This forum is quite old and I doubt the original forum user still checks this post

Thank you
Van L
NI Applications Engineer
0 Kudos
Message 6 of 15
(6,026 Views)

Hello Van,

Thanks for replying! I am a graduate student at Cal-State Northridge, working on making an interface for the 3D camera Swissranger SR3000. I have been able get 3D point cloud data using the "Call Library Function Node", but I haven't been able to get amplitude/reflectance values of the pixels for filtering purposes.

The function for acquiring amplitude image is as below;

void* SR_GetImage  ( SRCAM  srCam, unsigned char  idx)
Returns the pointer to the idx-th image. The idx has a value of 0 for distance image and 1 for amplitude image.

The srCam value is generated by the initialization function, which seems to be the memory block address of the camera being passed all along the subsequent functions. When I define the "void*" as "int32" at the SR_GetImage function it returns a similar value. So my question is, how would I be able to acquire the 176x144 amplitude data array at LabVIEW?

Could you please help?

Omer

0 Kudos
Message 7 of 15
(5,992 Views)

Hi Omer,

Is the returned value pointing to a 2D array?  If so, where in the code is that array created?  If a function allocates memory, this can cause memory issues.  It is best to allocate memory in LabVIEW by creating an array and then passing it as a parameter.  Is it possible to modify the function so the data is a parameter instead of a return value? 

Jennifer R.
National Instruments
Applications Engineer
0 Kudos
Message 8 of 15
(5,950 Views)

Hello Jennifer,

The returned value is pointing to a 176x144 array, which is acquired from the camera through;

“int SR_Acquire  ( SRCAM  srCam )”

where the return of the function is the amount of transfered bytes or a negative number if failed. And the memory allocation is controlled by functions such as;

                “int SR_SetBuffer  ( SRCAM  srCam, void *  buffer, size_t  size )”

The set buffer is used by functions like: SR_Acquire(), SR_CoordTrfFlt(), SR_GetImage() etc.

 

Since the DLL was provided with the camera without an open code, I do not beleive I would be able to change their functions. One possible solution was provided by LabVIEW on the phone, which was to make a DLL that takes the output of the camera's DLL (the pointer value) as its input and then de-reference it to return the actual data by using a function similar to “int output=*((int*)input)”. But as I am not familiar with C++ coding, I do not know what exact code to write for compiling into a DLL.

Could you please suggest how I may write the code or help me with another way of getting the array?

Thank you very much for your time!

Omer

0 Kudos
Message 9 of 15
(5,921 Views)

Hi Omer,

It sounds like memory allocation is being handled properly, which is important. 

Creating a wrapper DLL, as you mentioned, is a good approach.  You can write code to call SR_GetImage, get a reference to the array, and pass that to LabVIEW. 

Based on the details you have given, the function you write would probably look something like this:

void myWrapper (SRCAM  srCam, unsigned char  idx, double [ ][ ] imageArray)
{
  imageArray = SR_GetImage (SRCAM  srCam, unsigned char  idx);
}

Then create a 176x144 array in LabVIEW to pass to the Call Library Function Node for myWrapper, along with the other two parameters.  Select Array Data Pointer when configuring the Call Library Function Node.  You may also want to try declaring imageArray as a pointer to an array instead of the array itself. 

Jennifer R.
National Instruments
Applications Engineer
0 Kudos
Message 10 of 15
(5,840 Views)