Mixing managed/unmanaged in C++/CLI
-
I have a legacy C app which uses FFmpeg APIs. I'm trying to update it, I want to write a UI in C# and keep the core in C. So, i'm dabbling in C++/CLI for the first time. It's my understanding that I can create a managed class wrapper, and have managed methods which take managed parameters, convert them as necessary to unmanaged equivalents (with System.Runtime.InteropServices.Marshal methods), do the work in native C, and then convert outputs from unmanaged to managed types for return. However, I'm stuck at the start. I've created a class like this:-
ref class FFmpegCap
{
public:
FFmpegCap(String^ inputVideo);protected:
AVFormatContext *m_pFormatContext;};
In my constructor, i need to call a C FFmpeg function to initialise the library, one of the parameters it requires is of type AVFormatContext ** . So, I call this function as follows:-
if (av\_open\_input\_file(&m\_pFormatContext, pInputVideo ,NULL,0,NULL) != 0) { }
However, this fails to compile; error C2664: 'av_open_input_file' : cannot convert parameter 1 from 'cli::interior_ptr' to 'AVFormatContext **' It seems that the & operator is not doing what I expect of it! Any pointers? Thanks Jon
using System.Beer;
-
I have a legacy C app which uses FFmpeg APIs. I'm trying to update it, I want to write a UI in C# and keep the core in C. So, i'm dabbling in C++/CLI for the first time. It's my understanding that I can create a managed class wrapper, and have managed methods which take managed parameters, convert them as necessary to unmanaged equivalents (with System.Runtime.InteropServices.Marshal methods), do the work in native C, and then convert outputs from unmanaged to managed types for return. However, I'm stuck at the start. I've created a class like this:-
ref class FFmpegCap
{
public:
FFmpegCap(String^ inputVideo);protected:
AVFormatContext *m_pFormatContext;};
In my constructor, i need to call a C FFmpeg function to initialise the library, one of the parameters it requires is of type AVFormatContext ** . So, I call this function as follows:-
if (av\_open\_input\_file(&m\_pFormatContext, pInputVideo ,NULL,0,NULL) != 0) { }
However, this fails to compile; error C2664: 'av_open_input_file' : cannot convert parameter 1 from 'cli::interior_ptr' to 'AVFormatContext **' It seems that the & operator is not doing what I expect of it! Any pointers? Thanks Jon
using System.Beer;
There is a C++/CLI forum where you may get faster answers. Then again, one of the other people here may be typing an answer at the same time as me... Good luck, Iain
Codeproject MVP for C++, I can't believe it's for my lounge posts...
-
There is a C++/CLI forum where you may get faster answers. Then again, one of the other people here may be typing an answer at the same time as me... Good luck, Iain
Codeproject MVP for C++, I can't believe it's for my lounge posts...
Thanks Iain, I should use my eyes more I think.
using System.Beer;