Thread Subject: Cast calllib result to a struct pointer?

Subject: Cast calllib result to a struct pointer?

From: John Lyle

Date: 14 Nov, 2009 06:59:05

Message: 1 of 7

I have a DLL function that returns a char* but I need to cast this to a struct*. Specifically I am trying to use the cvGetSeqElem() function from OpenCV (http://opencv.willowgarage.com/documentation/dynamic_structures.html#cvGetSeqElem) like this:

cvRect = calllib('cxcore', 'cvGetSeqElem', cvSeq, 1);

where cvSeq is of type CvSeqPtr. This returns a string. How do I now cast this to a CvRect* to read the returned values? The MATLAB signature is:

[cstring, CvSeqPtr] = cvGetSeqElem(CvSeqPtr, int32)

Subject: Cast calllib result to a struct pointer?

From: roger

Date: 14 Nov, 2009 10:45:08

Message: 2 of 7

On Nov 14, 7:59 am, "John Lyle" <mathwo...@myallit.com> wrote:
> I have a DLL function that returns a char* but I need to cast this to a struct*. Specifically I am trying to use the cvGetSeqElem() function from OpenCV (http://opencv.willowgarage.com/documentation/dynamic_structures.html#...) like this:
>
> cvRect = calllib('cxcore', 'cvGetSeqElem', cvSeq, 1);
>
> where cvSeq is of type CvSeqPtr. This returns a string. How do I now cast this to a CvRect* to read the returned values? The MATLAB signature is:
>
> [cstring, CvSeqPtr] = cvGetSeqElem(CvSeqPtr, int32)

are you trying to typecast in matlab? better do it in c/c++ if you
can.
R

Subject: Cast calllib result to a struct pointer?

From: John Lyle

Date: 15 Nov, 2009 04:34:01

Message: 3 of 7

Yes I am, is that not possible? I'm trying to use the OpenCV DLLs directly in MATLAB without writing any C++ wrapper code.

roger <northsolomonsea@gmail.com> wrote in message <5badc0bd-f0dd-44e8-9153-b0975f7ffe2b@l2g2000yqd.googlegroups.com>...
> On Nov 14, 7:59?am, "John Lyle" <mathwo...@myallit.com> wrote:
> > I have a DLL function that returns a char* but I need to cast this to a struct*. Specifically I am trying to use the cvGetSeqElem() function from OpenCV (http://opencv.willowgarage.com/documentation/dynamic_structures.html#...) like this:
> >
> > cvRect = calllib('cxcore', 'cvGetSeqElem', cvSeq, 1);
> >
> > where cvSeq is of type CvSeqPtr. This returns a string. How do I now cast this to a CvRect* to read the returned values? The MATLAB signature is:
> >
> > [cstring, CvSeqPtr] = cvGetSeqElem(CvSeqPtr, int32)
>
> are you trying to typecast in matlab? better do it in c/c++ if you
> can.
> R

Subject: Cast calllib result to a struct pointer?

From: roger

Date: 15 Nov, 2009 10:52:28

Message: 4 of 7

On Nov 15, 5:34 am, "John Lyle" <mathwo...@myallit.com> wrote:
> Yes I am, is that not possible? I'm trying to use the OpenCV DLLs directly in MATLAB without writing any C++ wrapper code.
>
>
>
> roger <northsolomon...@gmail.com> wrote in message <5badc0bd-f0dd-44e8-9153-b0975f7ff...@l2g2000yqd.googlegroups.com>...
> > On Nov 14, 7:59?am, "John Lyle" <mathwo...@myallit.com> wrote:
> > > I have a DLL function that returns a char* but I need to cast this to a struct*. Specifically I am trying to use the cvGetSeqElem() function from OpenCV (http://opencv.willowgarage.com/documentation/dynamic_structures.html#...) like this:
>
> > > cvRect = calllib('cxcore', 'cvGetSeqElem', cvSeq, 1);
>
> > > where cvSeq is of type CvSeqPtr. This returns a string. How do I now cast this to a CvRect* to read the returned values? The MATLAB signature is:
>
> > > [cstring, CvSeqPtr] = cvGetSeqElem(CvSeqPtr, int32)
>
> > are you trying to typecast in matlab? better do it in c/c++ if you
> > can.
> > R

Typecasting in matlab is very basic and afaik you can't cast non
(matlab) base types, apart from that it's inefficiently implemented.
Better write a small wrapper, if typecasting is all it does it will be
easy enough.

Subject: Cast calllib result to a struct pointer?

From: John Lyle

Date: 16 Nov, 2009 05:35:02

Message: 5 of 7

OK thanks for your help

roger <northsolomonsea@gmail.com> wrote in message <5601f08d-e6c6-4fa1-8b24-f8f83c6c0c91@g23g2000yqh.googlegroups.com>...
> On Nov 15, 5:34?am, "John Lyle" <mathwo...@myallit.com> wrote:
> > Yes I am, is that not possible? I'm trying to use the OpenCV DLLs directly in MATLAB without writing any C++ wrapper code.
> >
> >
> >
> > roger <northsolomon...@gmail.com> wrote in message <5badc0bd-f0dd-44e8-9153-b0975f7ff...@l2g2000yqd.googlegroups.com>...
> > > On Nov 14, 7:59?am, "John Lyle" <mathwo...@myallit.com> wrote:
> > > > I have a DLL function that returns a char* but I need to cast this to a struct*. Specifically I am trying to use the cvGetSeqElem() function from OpenCV (http://opencv.willowgarage.com/documentation/dynamic_structures.html#...) like this:
> >
> > > > cvRect = calllib('cxcore', 'cvGetSeqElem', cvSeq, 1);
> >
> > > > where cvSeq is of type CvSeqPtr. This returns a string. How do I now cast this to a CvRect* to read the returned values? The MATLAB signature is:
> >
> > > > [cstring, CvSeqPtr] = cvGetSeqElem(CvSeqPtr, int32)
> >
> > > are you trying to typecast in matlab? better do it in c/c++ if you
> > > can.
> > > R
>
> Typecasting in matlab is very basic and afaik you can't cast non
> (matlab) base types, apart from that it's inefficiently implemented.
> Better write a small wrapper, if typecasting is all it does it will be
> easy enough.

Subject: Cast calllib result to a struct pointer?

From: Philip Borghesani

Date: 16 Nov, 2009 14:39:44

Message: 6 of 7

The best way to do this is with one or more aliases to the function cvGetSeqElem.

Generate a MATLAB file using loadlibrary with the mfilename option and edit the file to add aliases for the function with the return
types you are going to use.

See the bottom of the loadlibrary documentation for an example using mxGetNumberOfDimensions.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/loadlibrary.html

Phil

"John Lyle" <mathworks@myallit.com> wrote in message news:hdlkfp$773$1@fred.mathworks.com...
>I have a DLL function that returns a char* but I need to cast this to a struct*. Specifically I am trying to use the cvGetSeqElem()
>function from OpenCV (http://opencv.willowgarage.com/documentation/dynamic_structures.html#cvGetSeqElem) like this:
>
> cvRect = calllib('cxcore', 'cvGetSeqElem', cvSeq, 1);
>
> where cvSeq is of type CvSeqPtr. This returns a string. How do I now cast this to a CvRect* to read the returned values? The
> MATLAB signature is:
>
> [cstring, CvSeqPtr] = cvGetSeqElem(CvSeqPtr, int32)

Subject: Cast calllib result to a struct pointer?

From: John Lyle

Date: 14 Dec, 2009 07:16:09

Message: 7 of 7

Thanks Philip, that's exactly what I was looking for, works perfectly

"Philip Borghesani" <philip_borghesani@mathworks.spam> wrote in message <hdro7g$2t4$1@fred.mathworks.com>...
> The best way to do this is with one or more aliases to the function cvGetSeqElem.
>
> Generate a MATLAB file using loadlibrary with the mfilename option and edit the file to add aliases for the function with the return
> types you are going to use.
>
> See the bottom of the loadlibrary documentation for an example using mxGetNumberOfDimensions.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/loadlibrary.html
>
> Phil
>
> "John Lyle" <mathworks@myallit.com> wrote in message news:hdlkfp$773$1@fred.mathworks.com...
> >I have a DLL function that returns a char* but I need to cast this to a struct*. Specifically I am trying to use the cvGetSeqElem()
> >function from OpenCV (http://opencv.willowgarage.com/documentation/dynamic_structures.html#cvGetSeqElem) like this:
> >
> > cvRect = calllib('cxcore', 'cvGetSeqElem', cvSeq, 1);
> >
> > where cvSeq is of type CvSeqPtr. This returns a string. How do I now cast this to a CvRect* to read the returned values? The
> > MATLAB signature is:
> >
> > [cstring, CvSeqPtr] = cvGetSeqElem(CvSeqPtr, int32)
>

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
dll John Lyle 14 Nov, 2009 02:46:51
libpointer John Lyle 14 Nov, 2009 02:46:36
calllib John Lyle 14 Nov, 2009 02:46:25
opencv John Lyle 14 Nov, 2009 02:46:17
rssFeed for this Thread

Contact us at files@mathworks.com