【问题标题】:C++ throwing error through dll to c#C++ 通过 dll 向 c# 抛出错误
【发布时间】:2015-02-05 12:47:10
【问题描述】:

我创建了 C++ Dll

Initialize()
{
if(!_fs.isOpened())
    {
        throw ERROR_FILE_NOT_FOUND;
        _logfile << "Error ! Opening BDS.xml" << "\t" <<_arrivalTime<<endl;
        _logfile.close();
    }
}

并在 C# 中调用此函数

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        Initialize();
    }
    catch (RuntimeWrappedException ex)
    {
        MessageBox.Show(ex.Message);
    }
}

但我收到此错误 SEHException is Unhandled External Component has throw an exception 我尝试了 C# all exception 方法但我没有得到正确的答案。有人可以帮助我吗?或者告诉我如何从 C++ Dll 抛出异常并在 C# 中捕获相同的异常并等待 C# 的响应。像重试、中止、忽略错误一样,如果按下重试,它将再次开始在 Dll 中打开文件。我该怎么做。请帮我解决这个问题。

【问题讨论】:

标签: c# c++


【解决方案1】:

这是 C++\CLI 而不是 C++ 异常。在 C++\CLI 中,执行以下操作:

 throw gcnew System::Exception("It is a C++\CLI exception");

而不是 c++ 原生异常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多