setdatatype from void* to structPtr

3 views (last 30 days)
TS
TS on 25 May 2014
I have C code which is defining structs and some basic functions:
#include <mex.h>
#include "tst.h"
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray*prhs[] )
{
}
EXPORTED_FUNCTION S_another* returnStructPtr_explicit(S_input* arg){
return &arg->world;
}
EXPORTED_FUNCTION void* returnFloatPtr(S_input* arg){
arg->fnum=5.1;
arg->world.please = 5;
return &arg->fnum;
}
EXPORTED_FUNCTION void* returnStructPtr(S_input* arg){
return &arg->world;
}
And the Header file:
#ifndef _TST_H_
#define _TST_H_
#define EXPORT_FCNS
#ifdef EXPORT_FCNS
#define EXPORTED_FUNCTION __declspec(dllexport)
#else
#define EXPORTED_FUNCTION __declspec(dllimport)
#endif
typedef struct S_another
{
int please;
int help;
int to_solve;
int my_problem;
} S_another;
typedef struct S_input
{
float fnum;
S_another world;
} S_input;
EXPORTED_FUNCTION S_another* returnStructPtr_explicit(S_input* arg);
EXPORTED_FUNCTION void* returnFloatPtr(S_input* arg);
EXPORTED_FUNCTION void* returnStructPtr(S_input* arg);
#endif
After mexing and loading the library, the first 2 functions work well:
[a,b] = calllib('tst','returnStructPtr_explicit',sc);
a.Value
and
[a,b] = calllib('tst','returnFloatPtr',sc);
% Casting the datatype according to float
setdatatype(a,'singlePtr',1,1)
but the third function fails (at setdatatype) and crashes matlab:
[a,b] = calllib('tst','returnStructPtr',sc);
% for struct pointer value
setdatatype(a,'S_anotherPtr',1,1)
Any help will be greatly appreciated. Thanks

Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!