none
System.__ComObject and System.InvalidCastException RRS feed

  • Question

  • Hello,

    I have a simple VS2010 C# application where I want to use an old ocx written in CBuilder5.

    I added in the references and in the components in the toolbox, picking it from the COM objects.

    I am able to compile and use some of its methods and I get events through it. This ocx is supposed to connect to a DVR and get back the configuration info.

    After the connection, The ocx should automatically fill a struct with configuration values. As a matter of fact I can see through Wireshark the data passing, and the event  

    axDigiEyeIPX1_OnConnect(

    object sender, EventArgse) is fired. In this event handler, I thought it would be simple to retrieve the configuartion, Intellisense suggested me the fields as 

    string n1 = axDigiEyeIPX1.Config.Name1;

    I put a break point there and going over the Config word, I can see the message 

    with the following error: System.InvalidCastException: "Unable to cast COM object of type 'System.__ComObject' to interface type 'deipx.IDEConfig'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{68CEC0E9-5FE2-41D0-B4B8-4B44EFBA76E5}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

    deipx.ocx is the object I imported for which there is a Interop.deipx.

    Can anybody please give me some hints.

    Thanks a lot

    Marco


    marco furlan
    Monday, September 26, 2011 5:31 PM

All replies

  • check if the interop matches the OCX. And check if you are running the code in a STA thread.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Monday, September 26, 2011 6:55 PM
  • Hi, thanks for your reply.

    I left the standard setting of the simple C# WindowsForm application, that is

    [

    STAThread

    ]

     

    static void Main()

    and in the references I added Interop.deipx, which I think refers to the deipx.ocx object that I want to use.

    I believe that there might be problems marshaling C structures and unions from managed and unmanaged code. I saw that axDeipx.Config is a structure from which I should pick out fields, but I don't know if it is a union.

    What do you think ?


    marco furlan
    Tuesday, September 27, 2011 9:06 AM
  • The chance of a marshaling problem that corrupt memory in such a way that COM QI still work but returns E_NOINTERFACE is pretty small. 

    First update the ActiveX's registry and interop assembly by running regsvr32 and tlbimp.

    Then check the type library in OLEView. What is the type of the Config property? Does it support the 68CEC0E9-5FE2-41D0-B4B8-4B44EFBA76E5 interface? 

     

     

     



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Tuesday, September 27, 2011 11:17 PM
  • The chance of a marshaling problem that corrupt memory in such a way that COM QI still work but returns E_NOINTERFACE is pretty small. 

    First update the ActiveX's registry and interop assembly by running regsvr32 and tlbimp.

    Then check the type library in OLEView. What is the type of the Config property? Does it support the 68CEC0E9-5FE2-41D0-B4B8-4B44EFBA76E5 interface? 

     

     

     



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Tuesday, September 27, 2011 11:17 PM
  • Hi, thanks for your suggestions. I reregistered the ocx and nothing change. I'm not familiar with tlbimp, as far as I understand it creates a dll from a tlb file; I can't find any tlb file that resembles the name of the dll.

    With oleview, in Interfaces, I found IDEConfig with an interface = 68CEC0E9-5FE2-41D0-B4B8-4B44EFBA76E5, so things seems to match.

    Sorry to bother you, any further suggestion is very welcome

     


    marco furlan
    Wednesday, September 28, 2011 1:26 PM
  • ActiveX files contains type library too.

    Is the return type of the config property IDEConfig?



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Wednesday, September 28, 2011 6:19 PM