LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Borland C++ and DLL for LV

Hello,

I'm working on DLL (in Borland C++ Builder 6) for LabView (LabView 7.1)
which makes operations on double arrays;

1) When I try to use Adapt To Type when passing 1-D double (not complex)
array.

From LV we get declarations:

typedef struct {
long dimSize;
double elt[1];
} TD1;
typedef TD1 **TD1Hdl;

long _for_real(TD1Hdl input)

when I try to read dimSize everything is OK, also when I'm operating od int
(CV long) array everything is OK, I can fill matrix properly and there's not
problem in read data from matrix. When we change data type to double
something going wrong.
We use LV double 8-byte (15bit precision), and in BC++ also we use double
(8-byte, 15-bit precision). And we tried following methods to access data:

long _for_real(TD1Hdl input)
{
1) TD1 * tbl = * input;
1) tbl->elt[1] = 2.5;

2) (* (*input)).elt[1] = 2.5;

3) *((*(*input)).elt+1) = 2.5;
}

I writed this for one element, but in loops these methods don't work -
sometimes we get memory access violation, sometimes we get unbelively values
like 1.3E234, -5.3E334, 4.3E-275 and many similar (when we use loops to fill
data with the same values we get different when we're checking it in
LabView).

2) When against Adapt To Type we use pointer to 1-D double array, everything
is ok, we can modyfing data, read and what else we want.
long _for_real(double * input)
{
1) input[3] = 2.5;
2) *input(i+3) = 2.5;
}

Can anybody tells me what I'm doing wrong in my DLL? I thing that any error
I can make is in access to array by pointer, but these methods working very
good on integer arrays..

I'll be very thankful for any help or suggestions.

Best regards,
Darek


0 Kudos
Message 1 of 3
(2,718 Views)
I'm not sure if LV generates valid declarations. As far as I understand the struct below has exactly two elements, the dimSizes element and a pointer to an array of doubles of size one.

typedef struct {
    long dimSize;
    double elt[1];
} TD1;

However I think this is not valid. The array is stored so that there are first dimSizes which are of type long and then there is an array of datatype (doubles) right next to the dimsizes. So the doubles themselves are right after the dimsizes not a pointer to them. At least this is what I think. Correct me if I'm wrong here. I assume the following should work.

long _for_real(TD1Hdl input)
{
    double * array = &((*input)->elt);
    array[3] = 77.0;
    /* do what ever you want... but don't write outside allowed array indices */
}

If you need to resize the array, do it using NumericArrayResize. After the call to NumericArrayResize you must set the dimSize to it's correct value. If you try to first set the dimSize and the call NumericArrayResize, NumericArrayResize assumes that the array already is of correct size and doesn't allocate more memory and you'll end up in a memory access violation.

Message Edited by Tomi M on 06-09-2006 02:49 PM

--
Tomi Maila
0 Kudos
Message 2 of 3
(2,710 Views)

Hey,

thanks for reply

I've checked following function

typedef struct {
 long dimSize;
        complex elt[1];
 } TD1;

extern "C" __declspec(dllexport) int testFunction(TD1 * in)
{
 for (int i=0; i<100; i++)
  {
    (*((*tbl).elt+i)).re = 2;
    (*((*tbl).elt+i)).im = 3;
  }
return (*in).dimSize;
}

It works but now is problem with dimSize - this function returns 0; also access to imaginary data makes some weired things. I'll test many combinations of this solution in few days and I'll write here what happened and maybe I'll find the solution.
But if someone have some interesting idea, of course I'll try it.

Thanks for interesting of my problem,
Darek

0 Kudos
Message 3 of 3
(2,694 Views)