Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Capture stderr through P/Invoke

Capture stderr through P/Invoke

Scheduled Pinned Locked Moved C#
csharpc++debuggingjsonquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    K L K
    wrote on last edited by
    #1

    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;

    L 1 Reply Last reply
    0
    • K K L K

      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;

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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|


      K 1 Reply Last reply
      0
      • L Luc Pattyn

        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|


        K Offline
        K Offline
        K L K
        wrote on last edited by
        #3

        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;

        L 1 Reply Last reply
        0
        • K K L K

          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;

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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|


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups