LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a DLL taking a SAFERARRAY from LabVIEW

I am attempting to call from LabVIEW 7.1 a DLL written for and tested using Visual Basic.
It places values into a passed array, and is declared as follows:
C file: extern "C" __declspec(dllexport) HRESULT _stdcall Vlu5SerialReadBlock(DWORD addr, SAFEARRAY** ppSafeBuffer)
interface definition: HRESULT _stdcall Vlu5SerialReadBlock([in] LONG addr, [in,out] SAFEARRAY(unsigned char)* pBuffer);

This is recognised by LabVIEW (within the Call Library function node) as
long Vlu5SerialReadBlock(long addr, void *pBuffer);
where the type of pBuffer is "Adapt to Type (Handles by Value)".

When I pass a numeric array to the function and break the execution inside the DLL, I can see that instead of pointing to a SAFEARRAY, *ppS
afeBuffer points to the sequence of array elements preceded by the array size.

Is there any way of enticing LabVIEW to generate a SAFEARRAY, or should I rewrite the DLL to replace the SAFEARRAY references by simple "pointers to long"?

Many thanks
Nick
0 Kudos
Message 1 of 2
(3,044 Views)
The first would be to create a cluster with the same data types as a SAFEARRAY and use the to G DATA vi.


Here is the structure for a SAFEARRAY:


typedef struct tagSAFEARRAY
{
USHORT cDims;
USHORT fFeatures;
ULONG cbElements;
ULONG cLocks;
PVOID pvData;
SAFEARRAYBOUND rgsabound[ 1 ];
} SAFEARRAY;


So you could make a cluster with these same data types in it, in the same order. A USHORT is an unsigned short (U8), and ULONG is unsigned long (U32) and PVOID is a pointer to the data and SAFEARRAYBOUND is another cluster with this structure:


typedef struct tagSAFEARRAYBOUND
{
ULONG cElements;
LONG lLbound;
} SAFEARRAYBOUND;


Here's a web page that describes all the different paramters:


http://msdn.microsoft.com/library/wcedoc/wce
mfc/struct_25.htm

The second is possibly the better/easier way to do this. You could write a wrapper DLL that just uses the array, which is all you really care about. That way you wouldn't need to worry about creating the cluster just right.

Does that make sense?

(Thanks to Cyril Bouton on a similar forum thread at :
http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RNAME=ViewQuestion&HOID=5065000000080000000B410000&ECategory=LabVIEW.LabVIEW+General)

Thanks
Sacha Emery
National Instruments (UK)
// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 2 of 2
(3,044 Views)