U++ framework
Do not panic. Ask here before giving up.

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 previous 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 595 times)

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

Report message to a moderator

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


Current Time: Thu Sep 10 21:51:54 GMT+2 2026

Total time taken to generate the page: 0.00560 seconds