LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pointer as an input parameter in "call library function"

Hi!

I have a shared library (dll created in C++) that I
want to access with Call Library Function. One of the
function in this library needs a pointer to a memory
buffer as an input parameter in the following way:

long SetData(unsigned char *pbyData, unsigned short int *wDataLength);

- The parameter pbyData (type U8) points to a buffer that contains an array (type U8);

- wDataLength (int32) is the length of that array.

What should I connect on the input of this function? Let's say I have the array I want to feed in into this function, how do I do that?

Thanks in advance,
Ivan
0 Kudos
Message 1 of 4
(3,363 Views)
ivan_div wrote:

> Hi!
>
> I have a shared library (dll created in C++) that I
> want to access with Call Library Function. One of the
> function in this library needs a pointer to a memory
> buffer as an input parameter in the following way:
>
> long SetData(unsigned char *pbyData, unsigned short int *wDataLength);
>
> - The parameter pbyData (type U8) points to a buffer that contains an
> array (type U8);
>
> - wDataLength (int32) is the length of that array.
>
> What should I connect on the input of this function? Let's say I have
> the array I want to feed in into this function, how do I do that?

See my other post to your previous question.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 4
(3,363 Views)
I still didn't understand it...
0 Kudos
Message 3 of 4
(3,363 Views)
> long SetData(unsigned char *pbyData, unsigned short int *wDataLength);
>
> - The parameter pbyData (type U8) points to a buffer that contains an
> array (type U8);
>
> - wDataLength (int32) is the length of that array.
>
> What should I connect on the input of this function? Let's say I have
> the array I want to feed in into this function, how do I do that?
>


Double click or popup on the node and Configure. In the dialog, you
need to add parameters until you have two inputs and a return value.
For the return value, in the Type ring, choose Numeric -- the default
will be for an I32.

For the first parameter, change the name from arg1 to whatever you like,
it doesn't really matter except as documentation. Then set the Type to
Array. The fields below will default to I32, one dimension, and Array
Data Pointer. Change the I32 to U8.

For the second parameter, it should default to I32 by value. Change the
name as you please, change the Type to U16, and change the Pass to be
Pointer to Value.

That should be it for the dialog. The Function Prototype at the bottom
of the dialog should look similar to your first line above.

---

To wire things up on the diagram.

For the array, you will need an array of U8s. You can use a constant
sized to the correct size, or you can use Initialize array to build one
at runtime, or you can use Resize Array to take an existing Array and
set it to the correct initial size according to what the DLL expects.
There is no way for LV to know the initial assumption about the array
size, you have to read the DLL documentation and set it. If you set it
too small, the DLL writes past the end of the array and corrupts memory
either crashing immediately, stopping the VI with an error, returning an
error, or silently setting LV up to crash when things get unloaded. If
you want to make certain it is the correct size, put a probe on the
input wire or use execution hiliting to view the size of the input array.

Wire this array to the top input on the Call Library. For the second
parameter, wire up a U16, again it can be a constant, a control, or any
other wire of the correct type.

By the way, opening the help window, switching to the wiring or auto
tool and hovering over a wire gives lots of datatype information about a
wire.

You can also wire the right side of the Call Library. For the moment,
I'd just create indicators to view the results.

If you still have problems, please be specific as to which step causes
problems.

Greg McKaskle
0 Kudos
Message 4 of 4
(3,363 Views)