Capture stderr through P/Invoke
-
Hi, I have a native dll that I am interfacing through P/Invoke. I have created the API, but have no way to debug the native code. I tried using windbg for this, but couldn't figure out how. So, my current alternative is to have the native code print to stdout/stderr using fprintf. However, I can't find any way to see this output in C#. Is there a way to capture stdout/stderr output from the native code? klk
madness ? this.isSparta = true : this.isSparta = false;
-
Hi, I have a native dll that I am interfacing through P/Invoke. I have created the API, but have no way to debug the native code. I tried using windbg for this, but couldn't figure out how. So, my current alternative is to have the native code print to stdout/stderr using fprintf. However, I can't find any way to see this output in C#. Is there a way to capture stdout/stderr output from the native code? klk
madness ? this.isSparta = true : this.isSparta = false;
Hi, what I tend to do in such case is I pass a managed delegate that takes a string and logs it somehow; the unmanaged side accepts it as a pointer to a function that takes one char* as a parameter. Each time I want to log some native thing, I call the function pointer, and the managed world logs it (together with, and in sync with, the managed logging). Hence no capturing stdout/stderr, just passing a delegate. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
Hi, what I tend to do in such case is I pass a managed delegate that takes a string and logs it somehow; the unmanaged side accepts it as a pointer to a function that takes one char* as a parameter. Each time I want to log some native thing, I call the function pointer, and the managed world logs it (together with, and in sync with, the managed logging). Hence no capturing stdout/stderr, just passing a delegate. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
Hi Luc, I did what you said, and got it to work - so now I can get debugging output sent to the console. Thanks! It still feels like the old "printf" cycle of debugging (bug -> add printf -> recompile -> pray). Are there any guides on using WinDbg or another debugger to debug code that crosses managed->unmanaged boundaries? klk
madness ? this.isSparta = true : this.isSparta = false;
-
Hi Luc, I did what you said, and got it to work - so now I can get debugging output sent to the console. Thanks! It still feels like the old "printf" cycle of debugging (bug -> add printf -> recompile -> pray). Are there any guides on using WinDbg or another debugger to debug code that crosses managed->unmanaged boundaries? klk
madness ? this.isSparta = true : this.isSparta = false;
Hi,
K.L.K wrote:
I did what you said, and got it to work - so now I can get debugging output sent to the console. Thanks!
Fine. You're welcome.
K.L.K wrote:
It still feels like the old "printf" cycle of debugging (bug -> add printf -> recompile -> pray). Are there any guides on using WinDbg or another debugger to debug code that crosses managed->unmanaged boundaries?
I'm not an expert on WinDbg. I tend to include such log statement right from the start, and feel it saves me lots of hassles. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|