LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help Request: Passing 2D arrays to and from DLL

First, let me ask for your patience, as I am not
a C programmer, and my assistant C programmer is
not a LabVIEW programmer. I will try to be as
thorough as I can in my explanation. (By the way,
I know "alamda" is spelled wrong, but it's is
consistently wrong 🙂

I am calling a C function in a DLL. I have read
the application notes, and looked through recent
newsgroup posting, but have not seen this problem
addressed.

I am calling the C function "pidc" whose
declaration is shown below:

void DllExport pidc(float Vr,float *x,float
*y,float *z, float *sig,int ndata,float *a,int
ma,int *lista,int mfit,float **covar,float
**alpha,float *chisq,float *alamda)

{

*alamda += 2.0;
*chisq += 10.0;

x[1] = 1
.0
x[2] = 2.0

alpha[1][1] = 1000;
alpha[1][2] = 2000;
covar[1][1] =1000.0;
covar[2][2] = 2000.0;

return;

}

I am able to manipulate and pass back data in the
1D arrays (x,y,z,sig,a,lista), and numerics
(chisq, alamda), but when I manipulate data in
the 2D arrays (as shown above), LabVIEW crashes
(on the PC with the compiler, I get debugger
errors about failing to write to a memory
address).

The DLL is compiled with MS Visual C++ v6, and
I'm using LabVIEW 5.0.1 on Win98

The arrays are 0 filled to 3 X 3 dimensions prior
to calling the DLL.

I've tried passing the arrays by Array Data
Pointer, and by Array Handle (2 dimensions) but I
get memory errors either way. I've set the
calling convention to C.

In my limited capacity, I'm guessing that the
correct pointer is not getting to the C function,
and it's trying to write to some part of memory
that is a no-no.

Any suggestion?

Thanks,

-- Matt Dennie


Sent via Deja.com http://www.deja.com/
Before y
ou buy.
0 Kudos
Message 1 of 2
(3,203 Views)

Labview does not address 2D data as a pointer array to indivdual data arrays.

 

Labview address 2D data as one big 1D data array. (not you can always create your pointer array from the and address it as you have in your example). Our you can just follow the example I cut and pasted below.

 

taken from C:\Program Files\National Instruments\LabVIEW 7.1\examples\dll\data passing\Native Source\ARRAY2D.c

:

{
  int i, j;

  for(i = 0; i < array_length_row; i++)
  {
    for(j = 0; j < array_length_col; j++)
    {
      array[(i * array_length_col) + j] = array[(i * array_length_col) + j] *
                                          array[(i * array_length_col) + j];
    }
  }
}

Message 2 of 2
(2,611 Views)