Unable cast filter based on 4.0 framework to IBaseFilter.

no.Oby
2013-06-24
2013-07-12
  • no.Oby
    no.Oby
    2013-06-24

    I wrote my own filter, based on direct show wrap from codeproject. All works fine untill i change FW target to 4.0 and get invalid cast exception.

     
  • no.Oby
    no.Oby
    2013-06-27

    This filters works carrect in graphstudio and other.
    Any tips?

     
  • snarfle
    snarfle
    2013-06-28

    Is this the first time you've ever posted to a technical forum? Commonly people post a (brief) code sample along with specific steps needed to reproduce the behavior.

    What I have here is that you took some random project, made some unspecified changes, and it fails when you perform some operation about which you provide no details. Not much to go on...

     
  • no.Oby
    no.Oby
    2013-07-01

    Thanks for response,
    I'm writing a filter for converting yuy2 of regb32. Conversion calculations are performed in the shader using XNA.

    To create a filter I use baseclasses from codeproject. I have already written several filters based on these classes and they work fine in gpaphStudio graphEdit and directShowLib. Filters build for (3.0 - 3.5) Framework.
    To create a filter instance I use the auto generated code from gpaph edit plus:

        {
            filterName = filterName.ToLower();
            int hr = S_OK;
            DsDevice[] devices = DsDevice.GetDevicesOfCat(cotegoryGuid);
            foreach (DsDevice device in devices)
                if (device.Name.ToLower() == filterName)
                {
                    IBaseFilter filter = null;
                    IBindCtx bindCtx = null;
                    try
                    {
                        hr = CreateBindCtx(0, out bindCtx);
                        DsError.ThrowExceptionForHR(hr);
                        Guid guid = typeof(IBaseFilter).GUID;
                        object obj;
                        device.Mon.BindToObject(bindCtx, null, ref guid, out obj);
                        filter = (IBaseFilter)obj; /*here i get invalid cast error if try to cast filter with framework >= 4.0*/
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.ToString());
                    }
                    finally
                    {
                        if (bindCtx != null) Marshal.ReleaseComObject(bindCtx);
                    }
    
                    return filter;
                }
            return null;
        }
    

    Difference interface IBaseFilter in directShowLib and baseClasses from codeProject displayed on the image

     
    Last edit: no.Oby 2013-07-01
    • Eric
      Eric
      2013-07-02

      What is the return value of device.Mon.BindToObject ?
      Is "obj" non-null ?
      Why not creating the filter by its CLSID ?

       
      • no.Oby
        no.Oby
        2013-07-02

        Com object which successfuly casts to codeproject.IBaseFilter. I am sure that it`s return my filter.

         
        Last edit: no.Oby 2013-07-02
  • snarfle
    snarfle
    2013-07-02

    Looking at our samples where we use BindToObject, they don't use a BindCtx:

    pMon.BindToObject(null, null, ref g, out p);

    Might be worth a try.

     
    • no.Oby
      no.Oby
      2013-07-05

      Same Error.

       
  • no.Oby
    no.Oby
    2013-07-09

    Result filter (converter yuy2 => rgb32) works fine in graphStudio graphEdit, and throw error on creating in directshowlib.
    Maybe there is some better yuy2 convert filter?

     
    • Eric
      Eric
      2013-07-10

      Instead of using your method to create your filter, try to create it directly like that:

      [ComImport, Guid("11111111-2222-3333-4444-555555555555")] // Replace with your CLSID
      public class YourFilter { }

      IBaseFilter yourFilter = (IBaseFilter)new YourFilter();

      Make sure too that your registered filter type (x86/x64) match your application type.

       
  • no.Oby
    no.Oby
    2013-07-10

    Same problem. If i changing filter, which casts correctly on 3.5 for example, target framework to 4.0 filter can`t cast to IBaseFilter... So i think that problem in projects configuration(checked twice, mb some app.config advice), or in directsholib.

     
    • Eric
      Eric
      2013-07-11

      Your filter is registered with which framework version ?
      I'm not sure that a process can load 2 differents .Net runtime versions...

       
      • no.Oby
        no.Oby
        2013-07-12

        With 4.0.
        I think it can, a lot of dll in framework not updated since some versions.

         
        Last edit: no.Oby 2013-07-12
  • snarfle
    snarfle
    2013-07-10

    DirectShowNet doesn't perform the QueryInterface that occurs when casting COM objects. This is handled by the framework.