none
Interop - cast to IConnectionPointContainer fails RRS feed

  • Question

  • I'm trying to sink some COM events by using a Primary Interop Assembly provided with the Microsoft Device Simulation Framework. I get an exception when I hook up my C# event handler to the interop class thus:

    this.usbDevice.Endpoint0.OnReadTransfer += this.endpoint_OnReadTransfer 

    The exception is

    System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Dsf.SoftUSBEndpointClass' to interface type 'System.Runtime.InteropServices.ComTypes.IConnectionPointContainer'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B196B284-BAB4-101A-B69C-00AA00341D07}' failed due to the following error: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)).

    Sure enough, the SoftUSBEndpointClass doesn't implement the IConnectionPointContainer interface - although it does have the ComSourceInterfaces("Microsoft.Dsf.ISoftUSBEndpointEvents\0"), attribute applied (this was copied and pasted from Reflector including the trailing null). From looking around it appears that the ComSourceInterfacesAttribute may be related to IConnectionPointContainer, but I'm not really sure how.

    Can anyone suggest what might be going wrong here? My only guess is that the trailing '\0' may be preventing the COM interop from doing its stuff - but I'm no COM or interop expert so I may be completely on the wrong track. I can provide reverse-engineered IDL for the actual COM ISoftUSBEndpointEvents interface if that's any use.

    Sunday, February 8, 2009 3:34 PM

Answers

  • Hi
    Have the same problem as you. I think you are partly on the right track. I think that it does not implement IConnectionPointContainer simply because the underplaying object does not exist.  If you read the note in the documentation here:   http://msdn.microsoft.com/en-us/library/aa938727.aspx

    It say " You cannot use the Managed Interop Assemblies to create or modify simulated devices in managed code. You can use the Managed Interop Assemblies to create test applications that control the simulated devices."

    So if you want to create a new simulated device or modify a simulated device you are stuck with c++ atl/com
    :( .

     

    I think Microsoft needs change DSF so it supports c# .net all the way through.

     

    Basicly why I wanted to do an own device was to debug it together with my test application.

    I hope that i helped someone.

    • Edited by Nossnevs Wednesday, October 21, 2009 2:06 PM Microsoft font tag removed
    • Proposed as answer by Nossnevs Wednesday, October 21, 2009 2:08 PM
    • Marked as answer by Rich Tebb Wednesday, October 21, 2009 6:01 PM
    Wednesday, October 21, 2009 2:05 PM

All replies

  • Hi Rich,

    I am having the sample problem. Have you had any luck figuring this out?

    Thanks,

    Ken B.

    Monday, April 20, 2009 8:17 PM
  • No luck so far I'm afraid Ken, although I haven't had much chance to work on it recently (it's for a home rather than a work project). I'll keep you posted if I discover anything.
    Tuesday, April 21, 2009 9:28 PM
  • Any solution Rich?
    Thursday, July 9, 2009 8:55 AM
  • No, sorry, still haven't gotten around to working on this one yet.
    Thursday, July 9, 2009 7:04 PM
  • Hi
    Have the same problem as you. I think you are partly on the right track. I think that it does not implement IConnectionPointContainer simply because the underplaying object does not exist.  If you read the note in the documentation here:   http://msdn.microsoft.com/en-us/library/aa938727.aspx

    It say " You cannot use the Managed Interop Assemblies to create or modify simulated devices in managed code. You can use the Managed Interop Assemblies to create test applications that control the simulated devices."

    So if you want to create a new simulated device or modify a simulated device you are stuck with c++ atl/com
    :( .

     

    I think Microsoft needs change DSF so it supports c# .net all the way through.

     

    Basicly why I wanted to do an own device was to debug it together with my test application.

    I hope that i helped someone.

    • Edited by Nossnevs Wednesday, October 21, 2009 2:06 PM Microsoft font tag removed
    • Proposed as answer by Nossnevs Wednesday, October 21, 2009 2:08 PM
    • Marked as answer by Rich Tebb Wednesday, October 21, 2009 6:01 PM
    Wednesday, October 21, 2009 2:05 PM
  • Looks like that's the answer, Nossnevs. Now I'm going to need to brush up on my ATL/COM ...
    Wednesday, October 21, 2009 6:02 PM