Thread Subject: newbie question: how to pass enum pointer to calllib?

Subject: newbie question: how to pass enum pointer to calllib?

From: Ian Bell

Date: 6 Nov, 2009 00:03:04

Message: 1 of 2

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

Subject: newbie question: how to pass enum pointer to calllib?

From: Philip Borghesani

Date: 6 Nov, 2009 20:46:15

Message: 2 of 2

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

"Ian Bell" <ibell@instepsystems.com> wrote in message news:hcvp3o$7m1$1@fred.mathworks.com...
> 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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
enum pointer IB00 5 Nov, 2009 19:04:03
calllib IB00 5 Nov, 2009 19:04:02
rssFeed for this Thread

Contact us at files@mathworks.com