LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to pass a null pointer to a dll?

I want to read a string from a dll, but I do not know in advance the size of the string. The value returned by the function (dll) is the size of the string. The additional parameter is the string itself. If I could pass a null pointer to the dll, I could get the string size and then call the dll again, using a string with the correct dimension as input. How can I pass a null pointer to the dll?

the call is (stdcall): long GetLastErrorStr(CStr Last Error)

I made several tests. If the input string is too small, labview sometimes crashes. That's why I need to define in LV a string big enough to hold the C string returned by the dll.

Thanks
Message 1 of 5
(4,008 Views)
> I want to read a string from a dll, but I do not know in advance the
> size of the string. The value returned by the function (dll) is the
> size of the string. The additional parameter is the string itself. If
> I could pass a null pointer to the dll, I could get the string size
> and then call the dll again, using a string with the correct dimension
> as input. How can I pass a null pointer to the dll?
>
> the call is (stdcall): long GetLastErrorStr(CStr Last Error)
>
> I made several tests. If the input string is too small, labview
> sometimes crashes. That's why I need to define in LV a string big
> enough to hold the C string returned by the dll.
>


In reality, Null in C and most other languages is a pointer-sized zero.
So another way of doing
the call is to build the first DLL call with a
parameter of int32 and pass in a zero. Build the second DLL call for
CStr and pass in an initialized array of the size you need.

greg McKaskle
Message 2 of 5
(4,007 Views)
Thank you Greg, that's the solution. Passing a int32 with value zero to the dll gave me the size of the string.

Roland
0 Kudos
Message 4 of 5
(4,007 Views)
Assuming that a NULL pointer is really a 0x0 is somewhat bold. Especially with the segmented Intel architecture (OK, no longer en vogue). At least it is not good programming. And splitting the whole process in two DLL's is not ideal either. What if something happens between call 1 and 2?
Two options that I would favor:
1) Have a second parameter in the call giving a maximum stringlength and provide an empty buffer at entry. Then return the actual stringlenth and clip the string accordingly in labview.
2) Use Labview(Pascal)-strings, which have a length field included and re-allocate the buffer inside the DLL using CIN functions.

Gabi
7.1 -- 2013
CLA
0 Kudos
Message 3 of 5
(4,007 Views)
Thank you Gabi for your solutions. The problems is that I can not rewrite the dll. Of course option 1) works well if you write the dll specifically for LV.

best regards, Roland
0 Kudos
Message 5 of 5
(4,007 Views)