IMediaType.formatPtr to VideoInfoHeader?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a C++ application which does the following:

AM_MEDIA_TYPE l_MediaType;
pGrabber->GetConnectedMediaType(&l_MediaType);
// Get a pointer to the video header.
VIDEOINFOHEADER *pVideoHeader = (VIDEOINFOHEADER*)l_MediaType.pbFormat;

I beleive that in C# l_MediaType.pbFormat corresponds to
l_media_type.formatPtr. How can I convert the IntPtr resulting from there to
a VideoInfoHeader class in C#?
 
Joachim,

You wouldn't create a class, but rather a structure in .NET. I'll leave
the process of defining that correctly for interop with you.

Once you have that structure definition, you can call the static
PtrToStruct method on the Marshal class, passing the IntPtr which is the
pointer to the structure in memory. The PtrToStruct method will read the
unmanaged memory and marshal the information over into a new instance of
your structure.

Hope this helps.
 
I didn't need to define a structure. I just did the following:

VideoInfoHeader l_vih = new VideoInfoHeader();
Marshal.PtrToStructure(
l_media_type.formatPtr,
l_vih);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top