Discussion:
newbie question: how to pass enum pointer to calllib?
(too old to reply)
Ian Bell
2009-11-06 00:03:04 UTC
Permalink
1) Assume a C header file contains the following declarations:
typedef enum { e1, e2, e3 } MyEnum;
__declspec( dllimport ) int f1( MyEnum* p );

2) Assume the library containing this function has been loaded into Matlab and the Matlab function 'libfunctions 'MyLib' -full' declares this function as:
[int32, tMyEnumPtr] f1(tMyEnumPtr)

My question is, what parameters are to be passed to 'calllib' so the C function 'f1' can be successfully called. The following fails:
p = libpointer( 'tMyEnumPtr', 0 );
[ status, p ] = calllib( 'MyLib', 'f1', p );

Specifically, the above code generates the exception message:
identifier: 'MATLAB:libpointer:InvalidType'
message: 'Type was not found.'
stack: [3x1 struct]
cause: {}

Similarly, replacing ''tMyEnumPtr' with 'MyEnumPtr' also causes an error. What is the correct 'callib' parameter(s)?

Thanks,

Ian
Philip Borghesani
2009-11-06 20:46:15 UTC
Permalink
The simplest solution is to forget about the pointer and call:
[ status, changedval ] = calllib( 'MyLib', 'f1', 0 ); %matlab takes care of the pointer for you

If you want to use a pointer forget about the Ptr suffix
p = libpointer( 'tMyEnum', 0 );
[ status, p ] = calllib( 'MyLib', 'f1', p );
Numeric pointer types use the Ptr suffix to discriminate between scalar and matrix pointers but in general the Ptr suffix can be
dropped when a datatype is inside of a libpointer.

Phil
typedef enum { e1, e2, e3 } MyEnum;
__declspec( dllimport ) int f1( MyEnum* p );
2) Assume the library containing this function has been loaded into Matlab and the Matlab function 'libfunctions 'MyLib' -full'
[int32, tMyEnumPtr] f1(tMyEnumPtr)
My question is, what parameters are to be passed to 'calllib' so the C function 'f1' can be successfully called. The following
p = libpointer( 'tMyEnumPtr', 0 );
[ status, p ] = calllib( 'MyLib', 'f1', p );
identifier: 'MATLAB:libpointer:InvalidType'
message: 'Type was not found.'
stack: [3x1 struct]
cause: {}
Similarly, replacing ''tMyEnumPtr' with 'MyEnumPtr' also causes an error. What is the correct 'callib' parameter(s)?
Thanks,
Ian
Loading...