【问题标题】:FatalExecutionEngineError was detected检测到 FatalExecutionEngineError
【发布时间】:2010-03-19 10:13:55
【问题描述】:

在我的 .net 应用程序中使用非托管 dll 并获得异常时遇到问题 “运行时遇到致命错误。错误地址位于线程 0xbb4 上的 0x79e71bd7。错误代码为 0xc0000005。此错误可能是 CLR 中的错​​误,也可能是用户代码的不安全或不可验证部分中的错误。此错误的常见来源包括 COM-interop 或 PInvoke 的用户编组错误,这可能会损坏堆栈。”

我的代码在下面......

[DllImport("ITMSDLL.dll")]
internal static extern int get_month_mask(ref String theMask,ref  String theByt, int theSt_Dow, int theSt_Week, int theEn_Dow, int theEn_Week);

并通过C#中的以下方法调用此方法

public int GetMonthMask(ref String theMask,ref  String theByt, int theSt_Dow, int 
        theSt_Week, int theEn_Dow, int theEn_Week)
        {
            return CITMSDLLMethods.get_month_mask(ref theMask, ref theByt, theSt_Dow,  
                theSt_Week, theEn_Dow, theEn_Week);
        }

以上两种方法来自.net中的包装器dll。

上面的方法是通过下面的代码调用的

aRc = Utility.objCITMSDLL.GetMonthMask(ref aRetMask,ref aMByte, aSt_Dow, aSt_Wk, aEn_Dow, aEn_Wk);

调用此方法时会抛出异常“FatalExecutionEngineError was detected”和顶部指定的异常消息。

【问题讨论】:

    标签: .net


    【解决方案1】:

    当非托管方法在 char 缓冲区中返回字符串时,它通常映射到 .NET 中的 StringBuilder,而不是 String。

    这是 GetWindowText 的示例,直接来自 pinvoke

    int GetWindowText(HWND hWnd, LPTSTR lpString, int nMaxCount);

    变成:

    静态外部 int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

    【讨论】:

    • 您好,感谢您的回答。我尝试使用 String bulder,但它也没有帮助并抛出同样的错误。
    • 你应该发布方法的C定义;这样,这里的人们可以查看并建议不同的映射。
    • 其实我没有方法的定义,我只有.dll文件。此 dll 以前在 oracle .fmb 应用程序中使用。以下是oracle .fmb 文件中使用的定义。
    • fh_itms_get_mon_mask := ORA_FFI.REGISTER_FUNCTION(lh_USER,'get_month_mask',ORA_FFI.C_STD); ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_CHAR_PTR); ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_CHAR_PTR); ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_INT); ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_INT); ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_INT); ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_INT); ORA_FFI.REGISTER_RETURN(fh_itms_get_mon_mask,ORA_FFI.C_INT);
    • 字符串参数好像只是输入,所以在方法定义(和调用)中不要使用ref,而是继续使用String作为数据类型。
    猜你喜欢
    • 2013-11-17
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    相关资源
    最近更新 更多