Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing DLL operating on complex arrays

Hello,
 
I'm writing Dynamic Library (DLL) which should operate on complex matrix, and I have a problem with function parameters.
My target is DLL which uses FFTW libraries for calculating Fast Fourrier Transformate on complex signals given by matrix.
 
How should I define function? I make it on many ways,
 
extern "C" __declspec(dllexport) int fast_fourrier(fftw_complex * in, fftw_complex * out, int size)
extern "C" __declspec(dllexport) int fast_fourrier2(complex * in, complex * out, int size)
extern "C" __declspec(dllexport) int fast_fourrier3(TD1Hdl input, TD1Hdl output);
 
where TD1Hdl is
 
typedef struct {
 long dimSize;
 complex elt[1]; (or cmplx128 elt[1]; )
 } TD1;
typedef TD1 **TD1Hdl;
 
There's only one method which works:
extern "C" __declspec(dllexport) int function(double * re, double * im, double * re_out, double * im_out, int size);
But it's very time-consuming, because I must build another dynamic matrix and write into data from re and im. After calculating FFTW I must separate data onto re_out and im_out. But I think must be easier way to do this, but I'm don't now how to do this.
 
I'm don't know how to get into the data elt in structure TD1Hdl whitch is used by LabView when calling function on array 1D, type double 8-bytes by Array Handle. I can easily read the dimSize when we connecting to Call Library Function an array, but any modification on substructure elt crashes LabView. I think, that elt is pointer for first element of the matrix but maybe I'm wrong.
I show, that we can also pass a parameters by something like "Adapt to type", which is prototyped by function (void * arg1) and I have absolutely no idea what can I do with this param.
 
Maybe anybody has writed a external DLL operating on complex array and can help. I'll be grateful for any advices.
 
Best regards,
Darek
0 Kudos
Message 1 of 3
(4,593 Views)
You can pass your complex array into your DLL using the Adapt to Type parameter. The LabVIEW FFT VIs themselves pass complex arrays into the lvanalys.dll FFT function in the form of Adapt to Type - Handles by Value. You might try using this parameter. You should of course be careful when resizing arrays. If you have to do so, use the LabVIEW memory management functions declared in LabVIEW x.x\cintools\extcode.h to do so. This will inform LabVIEW that the resize has taken place so LabVIEW doesn't try to use the extended memory space later. This will save your application.

You can find much more information here. Hope this helps! Let us know how it comes along!
Jarrod S.
National Instruments
0 Kudos
Message 2 of 3
(4,574 Views)
OK, Something has moved forward.
 
I used this declaration:
extern "C" __declspec(dllexport) int fast_fourrier(TD1Hdl in)
 
where TD1Hdl is previously used structure. Similar code was generated when I tried "Create .c file" in LabView on Call Library Function Node set for Adapt to type.
LabView correctly passes array size, I have access to fields Im and Re of structure complex, I can write and read them but something is wrong with value conversion between LabView and DLL.
It looks like somewhere was difference in pointers, and pointer on first field of matrix wasn't it, but moved some bytes in any direction. I think that, because when I'm write to array in re and im fields the same value - for example 0.5 in LabView I get that there's about 2.5 E-234.
In next try I filled this matrix with sine function values in loop:
re = sin(2*i), im = sin(2*i+1). In worst way I should get set of values from range [-1,1] on the graph, but I get 0 or value which exceed 1.0E+100.
 
Could it be caused by compilator version? I'm using Borland C++ Builder 6.
 
I'm very thankful for interesting of this problem.
Darek
0 Kudos
Message 3 of 3
(4,563 Views)