From: Adrian on
I have the following structure which i pass to a C function via calllib

typedef struct tagRGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;

typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;

The C function will return 256 RGBQUAD to bmiColors. When matlab returns from function it crashehes at m_interpreter.dll.
I tried different way to declare the structure in header file like:
RGBQUAD bmiColors[256] but happened the same crash.
The only solution which works was to decarae it as:
BYTE bmiColors[256*4] and it works but this require to use a non standard header which is not acceptable.

Is this a limitation of matlab calllib?

Thank you in advance!
From: Adrian on

Also the definition of BYTE is:
typedef unsigned char BYTE, *PBYTE;

I also encounter a problem with a structure which has an array of structure (which has 2 float members). I can't get the value from a lib pointer.
From: Philip Borghesani on
The practice of placing an array of size 1 at the end of a structure and using it as a variable sized array is a non portable hack
frequently used in c programming but not supported by MATLAB. Instead of modifying the header it is possible to generate a loader
file and modify that. See the mfiilename option to LOADLIBRARY.
Arrays of a structure embedded within a structure are not supported ether so BYTE bmiColors[256*4] is the best you can do. Without
more information about the functions you are trying to call, your MATLAB code, and what MATLAB release you are running I can not
supply better answers or suggestions.

Phil

"Adrian " <adryyandc(a)yahoo.com> wrote in message news:hku905$rcc$1(a)fred.mathworks.com...
>I have the following structure which i pass to a C function via calllib
>
> typedef struct tagRGBQUAD {
> BYTE rgbBlue;
> BYTE rgbGreen;
> BYTE rgbRed;
> BYTE rgbReserved;
> } RGBQUAD;
>
> typedef struct tagBITMAPINFO {
> BITMAPINFOHEADER bmiHeader;
> RGBQUAD bmiColors[1];
> } BITMAPINFO, *PBITMAPINFO;
>
> The C function will return 256 RGBQUAD to bmiColors. When matlab returns from function it crashehes at m_interpreter.dll.
> I tried different way to declare the structure in header file like:
> RGBQUAD bmiColors[256] but happened the same crash.
> The only solution which works was to decarae it as:
> BYTE bmiColors[256*4] and it works but this require to use a non standard header which is not acceptable.
> Is this a limitation of matlab calllib?
>
> Thank you in advance!
>


From: Adrian on
Thank you very much Phil!
Your advice was of great importance.
I use MATLAB 2009a.


"Philip Borghesani" <philip_borghesani(a)mathworks.spam> wrote in message <hkun13$al1$1(a)fred.mathworks.com>...
> The practice of placing an array of size 1 at the end of a structure and using it as a variable sized array is a non portable hack
> frequently used in c programming but not supported by MATLAB. Instead of modifying the header it is possible to generate a loader
> file and modify that. See the mfiilename option to LOADLIBRARY.
> Arrays of a structure embedded within a structure are not supported ether so BYTE bmiColors[256*4] is the best you can do. Without
> more information about the functions you are trying to call, your MATLAB code, and what MATLAB release you are running I can not
> supply better answers or suggestions.
>
> Phil
>
From: Adrian on
I have told in this thread that array of structures in a structure are not supported yet by MATLAB calllib.

I have another realated question.
I have 2 structures:
typedef struct STRUCT1
{
int a;
int b;
}*PSTRUCT1;

typedef struct STRUCT2
{
int a;
int b;
char Name[20];
}*PSTRUCT2;

And i have 2 functions:
void test1(PSTRUCT1 array)
{
.................
}

void test1(PSTRUCT2 array)
{
.................
}

I know how much elements the array has.
I create first an array of structures in matlab and point to this array with libpointer.
While with STRUCT1 this works, with STRUCT2 this doesn't work.
I get the error: Only Structure arrays of simple data types are supported.
Is there a way to make this structure work with calllib?

voidPtr from matlab was not a solution either.

I have MATLAB 2009a. Are newer versions have better support for this issue.
 | 
Pages: 1
Prev: speech recognition using Wavelet
Next: GUI help