Nick Hewish wrote:
> The DLL interface definition is:
> HRESULT _stdcall GetErrorMessage([in] int hr,[out,retval] BSTR
> MsgOut);
>
> When the string is passed from LabVIEW to the DLL, the pointer MsgOut
> correctly points to the string, but the 4 bytes immediately preceding
> the string are all zero, rather than indicating the length of the
> string. This then causes problems when an attempt is made to point
> MsgOut from its existing buffer (freed using SysFreeString) to a new
> buffer (created using SysAllocString) containing the output text.
>
> Can you suggest how I can persuade LabVIEW to generate the string
> length and insert it where the BSTR definition requires?
There isn't a direct way in the LabVIEW Call Library Node. BSTR is a
ver
y specific Visual Basic datatype with some strange things to it as
well, such as a rather bad documentation about its inner workings
including the meaning of the hidden prepended length integer (bytes
or chars).
The only possible way I see is to actually allocate and deallocate
the buffer with the according WinAPI calls, really treating it as
a 32 bit integer (pointer) instead of a string in LabVIEW.
Alternative ways would be to create a byte array and do some magic
on it to get at its pointer but that is also quite involved and
actually less intuitive.
Rolf Kalbermatter
Rolf Kalbermatter
My Blog 
DEMO, Electronic and Mechanical Support department, room 36.LB00.390