Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. unhandled exception of type 'System.Runtime.InteropServices.SEHException' when trying to call C# dll from MFC

unhandled exception of type 'System.Runtime.InteropServices.SEHException' when trying to call C# dll from MFC

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++csharpcom
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PrasadHPShenoy
    wrote on last edited by
    #1

    Am getting 'An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in CallingExe.exe Additional information: External component has thrown an exception.' error when i try to call a dll generated with C# in my MFC code. Have successfully generated the .tlb file using RegAsm.exe and also installed it using gacutil. both these were successfull. Have attached my code for reference. MFC Code:

    #using <mscorlib.dll>
    #import "C:\\Programing\\Projects\\Visual Basic\\native calls\\vchash\\ManagedDLL\\ManagedDLL\\bin\\Debug\\ManagedDLL.tlb" raw_interfaces_only

    using namespace ManagedDLL;
    void CCallingExeDlg::OnBnClickedOk()
    {
    HRESULT hr = CoInitialize(NULL);
    ICalculatorPtr pICalc(__uuidof(ManagedClass));
    }

    C# Code:

    using System;
    using System.Runtime.InteropServices;

    namespace ManagedDLL
    {
    [ComVisible(true)]
    [Guid("1A9ECDD2-24FC-4f9b-97BF-BF170B16CB38")]
    // Interface declaration.
    public interface ICalculator
    {
    int Add(int Number1, int Number2);
    };
    [ComVisible(true)]
    [Guid("9CEFF09D-7140-451e-A85E-2341A7C978FA")]
    // Interface implementation.
    public class ManagedClass : ICalculator
    {
    public int Add(int Number1, int Number2)
    {
    return Number1 + Number2;
    }
    }
    }

    Am getting error in 'ICalculatorPtr pICalc(__uuidof(ManagedClass));' line of MFC code Am stuck with this from past two weeks. Any help would be greatly appreciated.

    Dhamu

    L 1 Reply Last reply
    0
    • P PrasadHPShenoy

      Am getting 'An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in CallingExe.exe Additional information: External component has thrown an exception.' error when i try to call a dll generated with C# in my MFC code. Have successfully generated the .tlb file using RegAsm.exe and also installed it using gacutil. both these were successfull. Have attached my code for reference. MFC Code:

      #using <mscorlib.dll>
      #import "C:\\Programing\\Projects\\Visual Basic\\native calls\\vchash\\ManagedDLL\\ManagedDLL\\bin\\Debug\\ManagedDLL.tlb" raw_interfaces_only

      using namespace ManagedDLL;
      void CCallingExeDlg::OnBnClickedOk()
      {
      HRESULT hr = CoInitialize(NULL);
      ICalculatorPtr pICalc(__uuidof(ManagedClass));
      }

      C# Code:

      using System;
      using System.Runtime.InteropServices;

      namespace ManagedDLL
      {
      [ComVisible(true)]
      [Guid("1A9ECDD2-24FC-4f9b-97BF-BF170B16CB38")]
      // Interface declaration.
      public interface ICalculator
      {
      int Add(int Number1, int Number2);
      };
      [ComVisible(true)]
      [Guid("9CEFF09D-7140-451e-A85E-2341A7C978FA")]
      // Interface implementation.
      public class ManagedClass : ICalculator
      {
      public int Add(int Number1, int Number2)
      {
      return Number1 + Number2;
      }
      }
      }

      Am getting error in 'ICalculatorPtr pICalc(__uuidof(ManagedClass));' line of MFC code Am stuck with this from past two weeks. Any help would be greatly appreciated.

      Dhamu

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You cannot directly use a managed dll from unmanaged code as far as I know. You need to take some other actions as detailed in some of these articles[^].

      Use the best guess

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups