03-11-2009 02:27 PM
Greetings, all,
I need to access a function in a Windows DLL. It returns a pointer to an array of characters. Does anyone know how I can use that pointer to get to the actual data?
Thanks,
03-11-2009 02:46 PM
AllenS wrote:Greetings, all,
I need to access a function in a Windows DLL. It returns a pointer to an array of characters. Does anyone know how I can use that pointer to get to the actual data?
Thanks,
Do you mean that the DLL allocates the pointer and returns it through a double referenced parameter?
Rolf Kalbermatter
03-11-2009 02:49 PM
03-11-2009 03:13 PM - edited 03-11-2009 03:14 PM
AllenS wrote:
Yes, the Call Library Function node takes a U32 as input, and returns a pointer in that U32. I assume the function is performing all of the allocations.
I assume that you have cofigured the U32 to be passed by reference. In that case there are basically two problems. First to get the information out of that pointer and then you should also know how the memory was allocated so you can call the according function to release it after you don't need it anymore.
To get at the actual string you need to call another function or in fact two since it is a C string pointer and you first have to get its length.
First you create a Call Library Node as follows:
Library: LabVIEW
Calling Convention: cdecl
Function: StrLen
return value: numeric, int32
1st arg: str, numeric, int32; pass by value, wire to this parameter your int32 pointer you got from your function
Then initialize an array of uInt8 with the length returned by this CLN.
A second CLN:
Library: LabVIEW
Calling Convention: cdecl
Function:MoveBlock
return value: void
1st arg: src, numeric, int32; pass by value, wire to this parameter your int32 pointer you got from your function
2nd arg: dest, array of uInt8, pass as C array pointer, the array you created with Initialize Array
3rd arg: len, numeric, int32, the length returned by the previous CLN
Now pass the array output of this CLN to a Byte Array to String node.
Alternatively if you know the maximum size that can be in the string pointer you can allocate an array of Bytes with that length, convert it into a String and then pass it to a CLN that is configured as follows:
Library: LabVIEW
Calling Convention: cdecl
Function:StrNCpy
return value: numeric, int32; the actual copied chars
1st arg: dest, string, pass as C pointer, the array you created with Initialize Array and converted with Byte Array to String
2nd arg: src, numeric, int32, pass by value, wire to this parameter your int32 pointer you got from your function
3rd arg: len, numeric, int32, pass by value, the length you allocated for the first parameter
Rolf Kalbermatter