From monthly archives: May 2007

We are pleased to present below all posts archived in 'May 2007'. If you still can't find what you are looking for, try using the search box.

Timothy

In VB.Net, sending output to the console from a Windows "Forms" application

Ever launched a forms app from the command line where you happily outputted debug code to the console from within Visual Studio, only to discover nothing is output to the command line like you expect?  Me too.  Really, it makes sense, though.  Forms apps in .Net run on their own thread and therefore detach from the initiating command line right after you hit enter.  Well how do you see all that pretty console text then?  Disable application framework **shiver**?  No...

You can do it using your old friend P/Invoke to access unmanaged code in kernel32.dll.

Here's the P/Invoke declarations:

Declare Function AttachConsole Lib "kernel32.dll" (ByVal dwProcessId As Int32) As Boolean
Declare Function FreeConsole Lib "kernel32.dll" () As Boolean

These functions allow you to attach and detach from an existing console session.  So how do you find out which console launched your WinForms app?  You don't need to.  If you specify "-1" as the process ID, it will automatically attach to the console that started the application.  Here's how you do it.

AttachConsole(-1)
System.Console.Writeline("I am writing to the console!")
FreeConsole()

Really, you probably will only attach once and free once in your app, but that's just example code up there.

One caveat: Since your app is running in its own thread, it will write to the console asynchronously.  This means that the user will receive a command prompt for the next command before your app writes anything to the console.  The console will not block waiting for your app to exit.  Be sure not to write things at strange times that will confuse the user about why strange text is appearing on the screen!

Source of information: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=983493&SiteID=1

Timothy

Screenshots of RD Tabs 2.0 Alpha

Check out the forums!  I posted screenshots of RD Tabs 2.0.  Let me know what you think in the forums and don't forget to vote!  :-)

http://forums.avianwaves.com/Default.aspx?g=posts&t=21

@avianwaves

Avian Waves on Twitter Avian Waves on Facebook Avian Waves on Spotify

Recent Comments
  1. Re: DPM 2016 + SQL 2016 and "An unexpected error occurred during the installation" ID: 4387
    Camilo: Edward comment solved the issue! After installing the 16.5.3 (from the link provided and without uninstalling...
  2. Re: It's Coming Any Day Now...
    Tim: Awesome to hear. Can't wait to check it out.
  3. Re: RD Tabs Security Advisory - 2.0 and 2.1 Beta
    Roman: Hi admin having same materiel as i need. Also get some extra stuff here: [url="hit5k.com"]Patch Applications...
  4. Re: RD Tabs Security Advisory - 2.0 and 2.1 Beta
    Roman: Hi admin having same materiel as i need. Also get some extra stuff here: Patch Applications
  5. Re: 3.0 is coming...
    Sean: Great news, can't wait!
  6. Re: DPM 2016 + SQL 2016 and "An unexpected error occurred during the installation" ID: 4387
    Funny Guy: To add my 2 cents - after a day of fight it appears that DPM installation uses WMI queries to detect...
  7. Re: DPM 2016 + SQL 2016 and "An unexpected error occurred during the installation" ID: 4387
    Funny Guy: To add my 2 cents - after a day of fight it appears that DPM installation uses WMI queries to detect...
  8. Re: DPM 2016 + SQL 2016 and "An unexpected error occurred during the installation" ID: 4387
    Funny Guy: To add my 2 cents - after a day of fight it appears that DPM installation uses WMI queries to detect...
  9. Re: DPM 2016 + SQL 2016 and "An unexpected error occurred during the installation" ID: 4387
    kAM aCOSTA: Thanks Edward !!!
  10. Re: 3.0 is coming...
    Dave: Very Cool!