I am writing a Windows CE application in C# that references a native C++ DLL (that I am also coding) using the following method:
[DllImport("CImg_IP_CE.dll")]
public static unsafe extern void doBlur(byte* imgData, int sigma);
This actually works fine but I am unable to debug the DLL. When I check the debug modules that are loaded after running the EXE, CImg_IP_CE.dll is not one of them. Even after calling functions successfully from the DLL it still does not show up in the modules list.
Upon looking around, it seems that the LoadLibrary() function might work, but I cannot find any examples of using this in a C# Windows CE application. How would I do this or is there a better way to make sure the DLL loads up for debugging?
I found the answer through this post:
http://www.eggheadcafe.com/conversation.aspx?messageid=31762078&threadid=31762074
In summary, the same question was asked and the response was:
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.
Further along in the thread, someone figured out how to accomplish this:
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.
So strangely, when you run the C# program and make a call to the native DLL code, it still does not show as loaded in the debug modules window. However, if you set the DLL project as the startup project, and then set the Remote Executable as the EXE file in the Debugging options, now when you first call the DLL, it will load up in the debugger. Okay... whatever works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With