c# - 在 Windows CE 的托管 C# 代码中加载 native DLL 作为调试模块

标签 c# c++ debugging interop windows-ce

我正在用 C# 编写一个 Windows CE 应用程序,它使用以下方法引用 native C++ DLL(我也在编写代码):

   [DllImport("CImg_IP_CE.dll")]
   public static unsafe extern void doBlur(byte* imgData, int sigma);

这实际上工作正常,但我无法调试 DLL。当我检查运行 EXE 后加载的调试模块时,CImg_IP_CE.dll 不是其中之一。即使从 DLL 成功调用函数后,它仍然没有出现在模块列表中。

环顾四周,LoadLibrary() 函数似乎可以工作,但我找不到在 C# Windows CE 应用程序中使用它的任何示例。我该怎么做,或者是否有更好的方法来确保加载 DLL 以进行调试?

最佳答案

我通过这篇文章找到了答案:

http://www.eggheadcafe.com/conversation.aspx?messageid=31762078&threadid=31762074

总而言之,提出了同样的问题,得到的答复是:

No, you can't step from managed code through a P/Invoke call into native code in the Smart Device debugger. You might be able to use Attach to Process to do the native debugging (with the native DLL project loaded into that instance of VS2005), or simply write debug information from the native DLL to a serial port or something. This really doesn't come up very often, though, where you actually need to step from one to the other.

在这个话题的后面,有人想出了如何完成这个:

A quick test shows that the easiest way to handle this is to 'run' your DLL. That is, set the debugging options to start the managed code EXE that will use your DLL and set your breakpoints in the DLL (all from the DLL project, of course). Naturally, when the EXE starts, your DLL won't be loaded, so you'll see the breakpoints as hollow circles with ! on them, but, when you call any of the native functions in your DLL, the DLL will be loaded (it's not loaded on startup), and the breakpoints will be set.

奇怪的是,当您运行 C# 程序并调用 native DLL 代码时,它仍然没有在调试模块窗口中显示为已加载。但是,如果您将 DLL 项目设置为启动项目,然后在调试选项中将远程可执行文件设置为 EXE 文件,那么当您首次调用 DLL 时,它将在调试器中加载。好吧……随便吧!

关于c# - 在 Windows CE 的托管 C# 代码中加载 native DLL 作为调试模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1112827/

相关文章:

c# - Visual Studio 2012 调试远程进程未按预期工作

c# - 使用 C# 获取当前国家和位置详细信息

c# - List<T> 需要 '1' 类型参数

c++ - 当 float 转换为 int 时,此代码中如何/为什么会发生缩小

c++ - 关于 Qt with C++ 的快速问题

javascript - WebStorm 调试器在断点处将 React 组件内的局部变量视为 'undefined',尽管它有一个值

c# - 如何在 winforms C# 中将数据从一种表单传输到另一种表单?

c# - 通过多个图片框循环多个图像

c++ - 指向引用参数的指针

调试时的 C++ 计时