LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How I pass a cluster with array of various data type (double, I32, string)

I have to pass from a VI to a Microsoft Visual C++ DLL, a cluster with some arrays of various data type. The problem is with Double array, that during Visual C debug is incorrect:the dimension is correct passed, but not array data. In the DLL I have inserted the C code genereted by LabVIEW. I tried to pass a cluster of only one array of double, and the results is the same. Then, I tried to pass a cluster with scalar number and the result is correct in only one case. If the double data is the first in the cluster, the result is correct; if the first is another data type, such as integer or boolean, the double data is incorrect during the debug of the DLL.
This is the code of my DLL:

// LabViewP
aram.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "LabViewParam.h"
#include "extcode.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}


typedef struct {
long dimSize;
double elt[1];
} TD2;
typedef TD2 **TD2Hdl;

typedef struct {
TD2Hdl elt1;
} TD1;


// This is an example of an exported variable
LABVIEWPARAM_API int nLabViewParamPass=0;

// This is an example of an exported function.
LABVIEWPARAM_API int LabViewParamPass(TD1 *pparam)
{
double parametro;
int i;
for (i=0;i<(**(*pparam).elt1).dimSize;i++)
{
parametro=(**(*pparam).elt1).elt[i];
}
return 42;
}

// This is the constructor of a class that has been exp
orted.
// see LabViewParam.h for the class definition
CLabViewParam::CLabViewParam()
{
return;
}


I use LabVIEW 7.0 and Windows XP.
Sorry for my english.
Thanks to every one for your suggestions.

Filippo
0 Kudos
Message 1 of 4
(3,390 Views)
> I have to pass from a VI to a Microsoft Visual C++ DLL, a cluster with
> some arrays of various data type. The problem is with Double array,
> that during Visual C debug is incorrect:the dimension is correct
> passed, but not array data. In the DLL I have inserted the C code
> genereted by LabVIEW. I tried to pass a cluster of only one array of
> double, and the results is the same. Then, I tried to pass a cluster
> with scalar number and the result is correct in only one case. If the
> double data is the first in the cluster, the result is correct; if the
> first is another data type, such as integer or boolean, the double
> data is incorrect during the debug of the DLL.

It is hard tell for sure, but you might have alignment problems. The
key symptom
is that you can pass a cluster of big and small fine, but
small big doesn't pass correctly. You might also test this by seeing
what the size of your struct is. For Boolean and Double, sizeof()
should return nine bytes no matter what order the array is in. If you
are getting different sizes, you have two options. You can either order
them such that the sizes work, or you can build the EXE or a wrapper DLL
so that the alignment matches LV's native alignment.

Greg McKaskle
0 Kudos
Message 2 of 4
(3,388 Views)
Thank a lot. The problem was effectively of alignement and the solution is to set the/Zp[n] compiler option that the default is 8 in Visual C++. With 1, data are passed correctly to the DLL.
0 Kudos
Message 3 of 4
(3,388 Views)

Hello Filippo,

could you tell me where i can set this option in .NET 2003? I have the same problem to pass a cluster including a double array to a DLL from LabView.

Thanks for your suggestions.

Eumel

0 Kudos
Message 4 of 4
(3,083 Views)