Replacing a unmanaged(MFC) COM server with a .NET COM server, used in unmanaged COM Clients (MFC)

1

I have a MFC COM server (ActiveX) and a MFC COM client. The server is build up from the following IDL:

library SomeLib
{
    importlib(STDOLE_TLB);

    [ uuid(some-guid),
    dispinterface ISomeIntf
    {
        methods:
            [id(1)] HRESULT Foo( );
    }
    
    [ uuid(some-guid),
    coclass SomeClass
    {
        [default] dispinterface ISomeIntf;
    };
}

The client is using Invoke, via the wrappers generated by the #import directive of the typelibary from the IDL (tlb created by MIDL), to call the function in the COM server.

I started on a replacement for the COM server in .NET. This is what I did:

  • using tblimp.exe to create a assemble describing the interface
  • created a C# class library, OM visible, and added a reference to the assemble created from the IDL
  • implemented a COM visible class deriving from the interface as defined in the assembly
  • Build and registered the .NET COM server

This is somehow the C# code:

using System;
using System.Runtime.InteropServices;

namespace SomeLibNS
{
  [ClassInterface(ClassInterfaceType.None), Guid("some-guid"), ProgId("SomeLibNS.SomeLib.1")]
  [ComVisible(true)]
  public partial class SomeLibCtrl : SomeLib
  {
        void Foo ()
        {
            // Do something right here
        }
  }
}

Now my problem...

All builds fine and when the COM client calls the function in the server, the function is executed. This means that COM related things to create and call the COM-server are working. The clients HRESULT on the Invoke is 0x80020005 (DISP_E_TYPEMISMATCH).
When I change the IDL not to return a HRESULT, rebuild client and server all works fine. When I dont use the assembly created by tlbimp and define my own interface, having the same signature as in the IDL, it works as well. According to the MS doc, HRESULT is translated to void, and failures in the server are reported by throwing exception, which are marshaled to a HRESULT. But this seems not t be the case, somehow??

What do I wrong, what do I not comprehend?

Thanks.

c++
.net
mfc
com
asked on Stack Overflow Aug 5, 2020 by user3445313

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0