Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Add capability to Log into Windows console
Add capability to Log into Windows console [message #10981] Thu, 09 August 2007 11:11 Go to next message
benoitc is currently offline  benoitc
Messages: 17
Registered: July 2007
Location: Nice (France)
Promising Member
Hi,

Windows has a hidden "console" that allow to output debug information in real time using the Win32 API "OutputDebugString".
The messages can then be viewed using DebugView tool from Sysinternals (see picture attached) (" http://www.microsoft.com/technet/sysinternals/utilities/debu gview.mspx" )
The code to activate that is quite simple (99% are from the LogStream code) and can be easily extended to Linux with a printf instead of OutputDebugString.
class ConsoleStream : public Stream {
	CriticalSection cs;
	byte  buffer[512];
	byte *p;

	void  Flush();
	void  Put0(int w);

protected:
	virtual void    _Put(int w);
	virtual void    _Put(const void *data, dword size);

public:
	virtual   bool  IsOpen() const {return true;};

	ConsoleStream()	{p = buffer;}
	~ConsoleStream(){}
};

void ConsoleStream::Flush()
{
	int count = (int)(p - buffer);
	if(count == 0) return;
	*p=0;
	::OutputDebugString((LPCSTR)buffer);
	
	p = buffer;
}

void ConsoleStream::Put0(int w)
{
	*p++ = w;
	if(w == '\n' || p == buffer + 511)
		Flush();
}

void ConsoleStream::_Put(int w)
{
	CriticalSection::Lock __(cs);
	Put0(w);
}

void  ConsoleStream::_Put(const void *data, dword size)
{
	CriticalSection::Lock __(cs);
	const byte *q = (byte *)data;
	while(size--)
		Put0(*q++);
}


Stream&  GetConsoleStream()
{
	static ConsoleStream s;
	return s;
}


GUI_APP_MAIN
{
    SetVppLog(GetConsoleStream());
	
    LOG(123);
}


It will be useful (at least for me) to have that in Upp.

Regards,
Benoit
  • Attachment: debugview.PNG
    (Size: 35.21KB, Downloaded 331 times)

[Updated on: Thu, 09 August 2007 11:15]

Report message to a moderator

Re: Add capability to Log into Windows console [message #11160 is a reply to message #10981] Fri, 24 August 2007 15:44 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thanks for an idea.

In the end, inspired by you, I have use a little bit different approach - see changelog.

Mirek
Previous Topic: bug: in Crypto/Sha1
Next Topic: Process Class wrapper for pipes in windows/linux
Goto Forum:
  


Current Time: Wed Apr 24 00:59:04 CEST 2024

Total time taken to generate the page: 0.04325 seconds