LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL Pointer to array

Hi!

 

I have a problem concerning a pointer used in a DLL file.

 

I just want to run a DLL, which processes 3DES encryption.. And the DLL hast a funktion called uint32_t GenerateRandomBytes(uint8_t *rnd_bytes, uint16_t num_bytes);

 

This is used to generate random bytes..Because of the fact that rnd_bytes is a pointer to an array.. i need to use an array at the input right? But this doesnt work..

 

Appended you will find my code..

 

KR

 

mexx

0 Kudos
Message 1 of 5
(2,567 Views)

It does work with an array, but unlike in LabVIEW where the LabVIEW compiler takes care to allocate your array when needed in the size needed, this doesn't work like that for C function calls. The C function can't allocate the array and hand it back to LabVIEW easily and LabVIEW does not know how big the array should be. So instead of allocating an array that in 99.999999% of the cases is either to short (and crashes) or way to big (and wasting memory resources) it leaves that task to you as the implementor of the VI using a Call Library Node.

 

What you need to do is allocating the array beforehand with the Initialize Array function, using the size that you pass as second parameter to the function as array size for the Initialize Array function. Then there is a valid memory buffer the function can write its data into.

 

And it's a nitpick but rnd_bytes is not a pointer to the array but the array itself or if you want to call it a pointer, it's the pointer to the array data.

Rolf Kalbermatter
My Blog
Message 2 of 5
(2,534 Views)

Thanks for answering that fast!

 

Ok so that means i have to initialize an array with the desired size.. and then give it's size to the function?..

 

The problem is that i can't chance the function in the DLL because i dont have the C code for that.. i just got the DLL and the header file where the prototype of the function is defined:

 

uint32_t GenerateRandomBytes(uint8_t* rnd_bytes,uint16_t num_bytes);

 

So i dont unterstand how to do it 😞

 

Maybe you can optimize my labview VI which is attached? Would be great!

 

KR

 

Markus

0 Kudos
Message 3 of 5
(2,513 Views)

 

Please take a look at this prototype:

 

uint32_t GenerateRandomBytes(uint8_t* rnd_bytes,uint16_t num_bytes);

 


 

What would you think of the second parameter num_bytes? Sounds to me like the size parameter that tells the function how big the array in the previous parameter is.

 

Of course this is just an educated guess and no guarantee. I haven't read the API documentation and there are about 500 other possibilities what this parameter could be used to for, but as a first guess it seems reasonable. Doesn't mean you don't have to read the API documentation and grok it too of course.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 5
(2,502 Views)

oh .. gg many thanks... yes you are right now its working!!

 

KR markus

0 Kudos
Message 5 of 5
(2,494 Views)