在Windows CE的托管C#代码中将本机DLL加载为调试模块

我正在使用以下方法在C#中编写一个引用本机C DLL(我也在编码)的Windows CE应用程序:

   [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#程序并调用本机DLL代码时,它仍未在调试模块窗口中显示为已加载.但是,如果将DLL项目设置为启动项目,然后在“调试”选项中将“远程可执行文件”设置为EXE文件,则当您首次调用DLL时,它将在调试器中加载.好吧…无论如何!

上一篇:android-Chrome远程调试,设备未显示


下一篇:c-分段故障处理程序中的分段故障