....
> So initializing my array to anything has the same result, the first 4
> bytes are missing. I can't use the cluster because it is a char **
> pointer and LV doesn't allow for this type--it just allows handles
> which returns the pointer, not the data.
>
....
> Those first 4 bytes are crucial, I can't believe LabVIEW is trashing
> them and my program...
>
This is one of those times when the type alone doesn't document the
interface that well. If the type were a char*, it would be for either
letting the DLL return a char, or for you to provide a buffer that the
DLL reads from, or for you to preallocate a buffer that the DLL will
write into. To tell the difference you have to find the documentation
of the function and hope they give details.
For a char**, this probably means that the DLL is allocating data and
returning the string to you. In otherwords, you are probably supposed
to provide a place for the DLL to return a char* (a string).
As you give the DLL different LV types, they always treat it the same
way and only give you four bytes that point to the string. While this
is close to a LStrHandle that LV uses, it isn't close enough, and there
is all sorts of damage being done to the datastructures. In all cases,
there is a memory leak of the string the DLL is allocating, and the
crashes with dataspace insanities and memory accesses mean that the DLL
is then writing over LV's data structures.
I don't have enough details to tell you the exact solution, but if
indeed the DLL is allocating a string and you are to hold onto it and
give it back, make the type of the DLL be an int32 by pointer. You will
not be able to see the string, but you can give it over to the DLL as
either the integer -- when they want it as a char*, and as an integer
pointer whenever they want it as a char** -- when they might resize it
and give you back a different pointer.
If you need to be able to read or affect the contents of the string,
then I think you will need a small DLL function where you pass in the
integer as well as a character count if the string is binary, and you
will also send in either a LV string handle or a presized LV string as a
string pointer. In the DLL function you copy the contents to the LV string.
Greg McKaskle