bsc2003

bsc2003

  • NA
  • 2
  • 0

C# DiretShow InterOp Woes

Apr 8 2004 9:14 AM
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); (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/htm/creatinganaudiocapturegraph.asp) 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# [Guid("A2104830-7C70-11CF-8BCE-00AA00A3F1A6"), InterfaceType(ComInterfaceType.InterfaceIsDual)] 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"; f.SetFileName(filepath,aa); 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.