gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:49:17 26 4
gpt4 key购买 nike

我正在用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com