Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# DiretShow InterOp Woes

Status
Not open for further replies.

SkintStudent

Programmer
Aug 22, 2001
4
GB
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#

[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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top