Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

C# DiretShow InterOp Woes

C# DiretShow InterOp Woes

C# DiretShow InterOp Woes

Hi there,

I'm trying to work out some coding which requires interacting with a COM object. I've read the MSDN documentation as well as those written by others, but am utterly confused. What I have got is this:

An object - FILE_WRITER which derives from DirectShow.IBaseFilter

From what I understand the FILE_WRITER has a parameter 'FileName' which can be set using an IFileSinkFilter.

This is a snippet of what the code would look like in C++

pWriter->QueryInterface(IID_IFileSinkFilter, (void**)&pSink);
pSink->SetFileName(L"C:\\MyWavFile.wav", NULL);


However I'm trying to do this in C#! I've figured out that C# has it's own QueryInterface function:

System.Runtime.InteropServices.Marshal.QueryInterface(retPtr,ref gid2,out retPtr2);

And using the Interop documentation I've managed to create the following interface in C#

interface IFileSinkFilter // cannot list any base interfaces here
int SetFileName(
[In, MarshalAs(UnmanagedType.LPWStr)]
string pszFileName,
[In, MarshalAs(UnmanagedType.LPStruct)]
AMMediaType pmt );

void GetCurFile();

BUT how do I fit all these pieces together??????

Here's what I've managed to put together so far...
DShowNET.IBaseFilter FILE_WRITER = (DShowNET.IBaseFilter) comObj;

project1.IFileSinkFilter f = (project1.IFileSinkFilter) FILE_WRITER;

DShowNET.AMMediaType aa = new AMMediaType();

aa.majorType = DShowNET.MediaType.Audio;

//CLSID for mp3 (I think - got it from my registry)
System.Guid gid3 = new Guid("098f2470-bae0-11cd-b579-08002b30bfeb");

aa.subType = gid3;
aa.formatType = FormatType.MpegStreams;

string filepath ="d:\\testfile.mp3";

At the moment I'm getting the error message when I run it that "Object reference not set to an instance of an object." This I think is referring to the object f.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close