How to get device moniker with a known class id?

1

I am using a DirectShowLib which is a thin wrapper for DirectShow. I have successfully enumerated BDA devices and collected their CLSIDs. Now when user selects a device by name and I know the chosen CLSID, I need to add this device to my filter graph.

I did the following:

Type type = Type.GetTypeFromCLSID(classid);
object device = Activator.CreateInstance(type);

Now the question is - what kind of object I got here in device? Debugger shows that it is a valid Com object. If I try to cast it to IBaseFilter, I get an exception "No such interface supported". I can cast it to IMoniker successfully. But then if I try to do the following:

int hr = graphBuilder.AddSourceFilterForMoniker(
    device, null, filtername, out receivedFilter);

I get an error:

HRESULT: 0x800401e4 (2147746276)
Name: MK_E_SYNTAX

I know that the method AddSourceFilterForMoniker works fine if I use it right after enumeration, so it seems I just do not create the moniker right.

What is the right way to create moniker object if class id is known, so I can pass it to the AddSourceFilterForMoniker?

c#
directshow
moniker
asked on Stack Overflow Feb 28, 2010 by JustAMartin • edited Feb 28, 2010 by casperOne

1 Answer

1

Just a guess, but it appears you are not creating an IBindCtx implementation. All operations that involve IMoniker that I've seen require a IBindCtx implementation to be passed in order to provide context for operations involving the moniker.

That being said, the AddSourceFilterForMoniker method is no different, in that you aren't passing a bind context for the moniker.

answered on Stack Overflow Feb 28, 2010 by casperOne

User contributions licensed under CC BY-SA 3.0