@daras wrote:
I've tried writing DLL in
Borland C++ Builder 6, but there were errors with access to complex
data. So, I've changed compilator on MS Visual C++ 6.0 and here also
I'cant change the complex data. I've defined following structures:
typedef struct {
double re;
double im;
} Complex64;
typedef struct {
int dimSize;
Complex64 cmplx[0];
} ComplexArr;
typedef ComplexArr **ComplexHdl;
and simple function like that:
extern "C" __declspec(dllexport) int MyComplexFunction(ComplexHdl arr)
{
int size = (*arr)->dimSize;
Complex64 * cmplx = (*arr)->cmplx;
double tmp;
for (int i = 0; i < size; i++, cmplx++)
{
cmplx->re *=2;
cmplx->im *=3;
}
return size;
}
I can't change anything complex data, these settings just don't
work. Is there anybody who now what's going on and what I should change
to fix it? I attach also picture with LabView block diagram, because
maybe there I do something incorrectly..
A few things to check:
1) Have you made sure the Call Library Node has configured the array parameter as Adapt to Type, Handles by Value?
2) In your example code you use the loop variable i but don't declare it. A C compiler won't be able to compile this.
3) Make sure you use byte alignement. LabVIEW byte packs data
structures, whereas Visual C (and probably Borland C) by default will
use 8 byte alignement. This means that a DLL created with Visual C will
align the Complex array element cmplx[0] in your ComplexArr structure
to 8 bytes (the size of the double value inside the Complex64
structure) while LabVIEW will just pack it and place the first complex
element at offset 4 in the ComplexArr structure, resulting in total
misalignment and therefore rubbish between your DLL and LabVIEW.
You can set the default alignment of Visual C in the project settings
under C/C++->Code Generation (Visual C 6.0) or maybe even better yet
add a
#pragma pack(1)
<your type declarations for structures that you want to receive from LabVIEW>
#pragma pack()
to your source file. Borland C has similar makros but not exactly the same. They specifically don't use #pragma.
Rolf Kalbermatter
Message Edited by rolfk on 07-06-2006 10:13 AM
Rolf Kalbermatter
My Blog 
DEMO, Electronic and Mechanical Support department, room 36.LB00.390