unhandled exception of type 'System.Runtime.InteropServices.SEHException' when trying to call C# dll from MFC
-
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_onlyusing 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
-
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_onlyusing 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