Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot convert parameter 1 from 'cli::interior_ptr<Type>' to 'CvCapture **'

I am capturing a video frame as follows

CvCapture *capture = cvCreateFileCapture("PATH");

I can read the video and process it. Everything works fine. But when I try to release the capture

cvReleaseCapture( &capture ); 

I get

error C2664: 'cvReleaseCapture' : cannot convert parameter 1 from
 'cli::interior_ptr<Type>' to 'CvCapture **'
          with
          [
              Type=CvCapture *
          ]
          Cannot convert a managed type to an unmanaged type

The function is inside a class.

public ref class Locator

and I am calling it from the main

Locator r;

Before I added it *public ref * to class locator it was not giving me any error.

Any ideas for fixing it? It was working fine before switching to c++-cli.

I think it is related to some heap problem, items on the heap can be moved as a result of garbage collection. In order to send a pointer to a native method/function, you need to “pin” the pointer for the duration of the call, but I don't know how.

Thanks.

Updated:

That fixed it.

pin_ptr<CvCapture*> p;
p = &capture;
cvReleaseCapture( p );  
like image 322
fmvpsenior Avatar asked Jul 20 '12 17:07

fmvpsenior


1 Answers

(Adding as answer, thanks to @AlexFarber for the correction)

Have you tried pin_ptr? Something like:

pin_ptr<CvCapture*> pCapture = &capture;
like image 70
Chris O Avatar answered Nov 14 '22 21:11

Chris O