- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是我得到执行错误的行:
NimbieImportedFunctions.BS_Robots_Connect(
out robotCount, out robotIDs, out robotTypes, out robotReadys);
还有 DllImport 本身:
[DllImport("BSRobots20.DLL", CallingConvention = CallingConvention.Cdecl)]
public static extern UInt32 BS_Robots_Connect(
out int nRobotCount,
out int[] pnRobotIDS,
out int[] pnRobotTypes,
out bool[] pbRobotReadys);
从头文件中:
extern "C" __declspec(dllexport) DWORD BS_Robots_Connect(
int *nRobotCount,
int *pnRobotID,
int *pnRobotType,
bool *pnRobotReady
);
//
// Description:
// Function to connect all online robots.
//
// Parameters:
// nRobotCount [out] Pointer to an integer that receives the number of robots.
// pnRobotID [out] Pointer to an array of integer that receives the robot IDs.
// pnRobotType [out] Pointer to an array of integer that receives the robot types.
//
// Return:
// BS_ROBOTS_OK If the function succeeds with no error.
// BS_ROBOTS_ERROR If the function fails with any error occurred.
//
///////////////////////////////////////////////////////////////////////////////
我得到的错误:
The runtime has encountered a fatal error. The address of the error was
at 0x72c4898e, on thread 0xdf0. The error code is 0xc0000005.
This error may be a bug in the CLR or in the unsafe or non-verifiable portions
of user code. Common sources of this bug include user marshaling errors for
COM-interop or PInvoke, which may corrupt the stack.
有时,我也会收到 AccessViolationException。我非常不确定发生了什么。请帮助我!
最佳答案
您的 p/invoke 不正确。或许应该这样写:
[DllImport("BSRobots20.DLL", CallingConvention = CallingConvention.Cdecl)]
public static extern uint BS_Robots_Connect(
out int nRobotCount,
[Out] int[] pnRobotIDS,
[Out] int[] pnRobotTypes,
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1)]
[Out] bool[] pbRobotReadys
);
nRobotCount
应该是 ref
而不是 out
是合理的。根据您是否需要将信息传递到函数中来确定。你确定 pbRobotReadys
是一个数组吗?如果不是,则使用 out bool
或 ref bool
。
所以也许你需要的是:
[DllImport("BSRobots20.DLL", CallingConvention = CallingConvention.Cdecl)]
public static extern uint BS_Robots_Connect(
ref int nRobotCount,
[Out] int[] pnRobotIDS,
[Out] int[] pnRobotTypes,
[MarshalAs(UnmanagedType.U1)]
out bool pbRobotReadys
);
要深入了解这一点,您需要更多地研究文档,并可能引用您可以找到的任何 C++ 示例代码。
您需要在调用函数之前分配数组。我无法从这里判断您究竟需要如何分配数组。想必您知道它们需要多大。
为什么你的版本不对?嗯,考虑这个问题的方式是 C# 数组已经是一个引用。通过使用 out
传递数组,您将传递一个指向指针的指针。换句话说,一级间接太过分了。
另一种思考方式是您要求非托管代码创建托管数组。而这显然是它做不到的。
关于c# - DllImport 期间出现 FatalExecutionEngineError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22966893/
我收到以下错误: Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'C:\Users
今天我正在调试我的一些代码,这些代码构建了一些 ExpressionTrees,将它们编译为可调用的委托(delegate),然后在需要时调用它们。在执行此操作时,我遇到了 FatalExecutio
我在尝试将许多 DBase IV 文件中的 memofields 中的 C++ 结构读取到 C# (.Net 4) 中,然后将它们插入 MSSQL 2008 中时遇到了问题。数据正在从 DBase 文
这是我得到执行错误的行: NimbieImportedFunctions.BS_Robots_Connect( out robotCount, out robotIDs, out robotT
当我调试 ASP.NET MVC 应用程序时,KeyVaultClient 随机抛出异常: Managed Debugging Assistant 'FatalExecutionEngineError
托管调试助手“FatalExecutionEngineError”:“运行时遇到 fatal error 。错误的地址是 0x641ad419,在线程 0x5d0c 上。错误代码是 0xc000000
我需要在 C# 中使用 win32 NetLocalGroupGetMembers。我找到并测试了三种解决方案。这三个都因 FatalExecutionEngineError 而失败。框架是.net
我正在用 C# 例程试验一个我无法解决的乏味问题。我正在开发一个应用程序,它使用 GDAL 库(一个用 C++ 编写的 DLL 库来操作地理数据)打开 ESRI ShapeFile,并在 Pictur
几周(几个月?)以来,在 Visual Studio 2017/2019 Enterprise 中重新启动我的 ASP.NET 应用程序后,我有时会遇到以下异常。只有当 IIS Express 已经在
我正在开发一个连接到 MySQL 数据库的 C#.NET 应用程序,并使用一些不安全的代码来使用旧的 C++ dll。 程序一启动,就会加载dll并分配一个指针,然后初始化一些C#变量,然后删除指针。
作为我论文的一部分,我正在开发一个客户端/服务器应用程序,并选择使用 SocketAsyncEventArgs 来获得网络操作方面的最大性能。今天下午,我决定对创建 20 个线程并为每个线程发送 10
在我的程序中这一行: int value = MTEConnect(auth_string, err); 我收到这样的异常: FatalExecutionEngineError The runtime
我们正在使用一个封装数值的结构,我发现当在表达式中使用该结构的可空版本时,会发生 FatalExecutionEngineError: Additional information: The runt
我即将为用 VBScript 编写的遗留系统启动一个正在工作的迁移项目。它有一个有趣的结构,其中大部分是通过将各种组件编写为“WSC”文件来隔离的,这实际上是一种以类似 COM 的方式公开 VBScr
我正在研究无锁堆栈和队列数据结构,我可以在其中放置任意数量的添加项目并在一次调用中收集所有项目,我认为我的设计是可靠的并且它按预期工作直到我开始收到一个意外的异常,我认为这在纯 C# 环境中是不可能的
在 AnyCPU 或 x86 上,我可以运行这个程序,在 Foo 上设置一个断点,将第一个参数从 0.5f 编辑到 0.6f,然后恢复就好了。 但是,在 x64 上,它在恢复时始终因 FatalExe
我有以下基本 XAML: 当我尝试关闭包含用户控件的选项卡时,出现以下错误: Managed Debugging Assistant 'FatalExecut
这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the h
当我尝试调试我的项目时,我不断收到此错误消息。相同的代码适用于大学机器。我目前使用 Windows 8.1 和 resharper 8.2,并在 selenium 测试中使用了最初的几种方法。我也在使
我正在尝试(为了好玩)将 String.Empty 重新定义为单个空格“”。为什么这会破坏 CLR 框架? 留言: The runtime has encountered a fatal error.
我是一名优秀的程序员,十分优秀!