Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, degenerate_762, ozgur), 1,311 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Debugconsole(including printf override) #415852
01/24/13 17:21
01/24/13 17:21
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline OP
Serious User
Rackscha  Offline OP
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
Hi, found this small lite-c script, i created a while ago, on my hdd. Thought it might be helpfull for others:

Click to reveal..
Code:
#ifndef Console_c
	#define Console_c
	#include<windows.h>;

	long WINAPI WriteConsole(int Handle, char* Buffer, int CharsToWrite, int* CharsWritten, int reserved);
	long WINAPI CreateConsoleScreenBuffer(
	long dwDesiredAccess,
	long dwShareMode,
	long *lpSecurityAttributes,
	long dwFlags,
	long lpScreenBufferData
	);

	long WINAPI SetConsoleActiveScreenBuffer(
	long hConsoleOutput
	);

	long GConsoleBuffer;

	void printf(char* AText)
	{
		WriteConsole(GConsoleBuffer, AText, str_len(AText), NULL, 0);	
	}

	void _main();

	void main()
	{
		AllocConsole();
		GConsoleBuffer = CreateConsoleScreenBuffer(GENERIC_WRITE, FILE_SHARE_READ, 0, CONSOLE_TEXTMODE_BUFFER, 0);
		SetConsoleActiveScreenBuffer(GConsoleBuffer);	
		_main();	
	}

	#define main _main
#endif



add this file as the FIRST one. Its going to register the console, and redeclaring printf (only for one parameteer though)

you are wondering about my void main()?

don't worry. the
Code:
void _main()


predeclaration before and the
Code:
#define main _main


at the end allow me to "hook" you'r main. My main is executed before you'r main(which is required to get a working printf in you'r main, as startup functions are executed AFTER main -.-)

Last edited by Rackscha; 01/24/13 17:23.

MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: Debugconsole(including printf override) [Re: Rackscha] #415854
01/24/13 19:41
01/24/13 19:41
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You say I should include that file before acknex.h? Then I will get a syntax error in windows.h at line 6519 (RECT). What am I doing wrong?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Debugconsole(including printf override) [Re: Superku] #415869
01/25/13 00:19
01/25/13 00:19
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
just took a short look but try to remove the ; on the include statement grin


Visit my site: www.masterq32.de
Re: Debugconsole(including printf override) [Re: MasterQ32] #415871
01/25/13 00:39
01/25/13 00:39
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Sadly this does not change anything.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Debugconsole(including printf override) [Re: Superku] #415874
01/25/13 05:22
01/25/13 05:22
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

I think you need to include it after acknex.h, he is just explaining that the #define inside the code will not destroy yours.

I tried it and it is working. Thanks for the script.

Re: Debugconsole(including printf override) [Re: 3dgs_snake] #415882
01/25/13 08:17
01/25/13 08:17
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline OP
Serious User
Rackscha  Offline OP
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
mh strange, i'll look into it. At home it worked to use it before acknex.h o.O

EDIT: My advice to use it before acknex.h wasd to the efefct to override even printf statements left/used in acknex native header/c files wink
(like the current Physx headers, which will be fixed by jcl)


Last edited by Rackscha; 01/25/13 08:18.

MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: Debugconsole(including printf override) [Re: Rackscha] #458229
02/28/16 11:16
02/28/16 11:16
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Made some changes to it, now it's a little more usable IMO:

Code:
#ifndef Console_c
	#define Console_c
	#include<windows.h>;

	long WINAPI WriteConsole(int Handle, char* Buffer, int CharsToWrite, int* CharsWritten, int reserved);
	long WINAPI CreateConsoleScreenBuffer(long dwDesiredAccess, long dwShareMode, long *lpSecurityAttributes, long dwFlags, long lpScreenBufferData);
	long WINAPI SetConsoleActiveScreenBuffer(long hConsoleOutput);
	long GConsoleBuffer;
	int consoleInitialized = 0;

	void consoleInit()
	{
		if(consoleInitialized) return;
		consoleInitialized = 1;
		AllocConsole();
		GConsoleBuffer = CreateConsoleScreenBuffer(GENERIC_WRITE, FILE_SHARE_READ, 0, CONSOLE_TEXTMODE_BUFFER, 0);
		SetConsoleActiveScreenBuffer(GConsoleBuffer);	
	}

	void cdiag(char* AText)
	{
		WriteConsole(GConsoleBuffer, AText, str_len(AText), NULL, 0);	
	}
	
	#define cprintf0(str) cdiag(_chr(str))
	#define cprintf1(str,arg1) cdiag(_chr(str_printf(NULL,str,arg1)))
	#define cprintf2(str,arg1,arg2) cdiag(_chr(str_printf(NULL,str,arg1,arg2)))
	#define cprintf3(str,arg1,arg2,arg3) cdiag(_chr(str_printf(NULL,str,arg1,arg2,arg3)))
	#define cprintf4(str,arg1,arg2,arg3,arg4) cdiag(_chr(str_printf(NULL,str,arg1,arg2,arg3,arg4)))
	#define cprintf5(str,arg1,arg2,arg3,arg4,arg5) cdiag(_chr(str_printf(NULL,str,arg1,arg2,arg3,arg4,arg5)))
#endif



Call
consoleInit()
to init the console window, then use the cprintfN functions to print formatted strings (with N arguments) to the console:
cprintf1("\nenemy loop at frame %d",(int)total_frames);


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Debugconsole(including printf override) [Re: Superku] #458230
02/28/16 12:18
02/28/16 12:18
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Or an alternative version which does "everything" on its own:

Code:
#ifndef Console_h
	#define Console_h
	#include<windows.h>;

	long WINAPI WriteConsole(int Handle, char* Buffer, int CharsToWrite, int* CharsWritten, int reserved);
	long WINAPI CreateConsoleScreenBuffer(long dwDesiredAccess, long dwShareMode, long *lpSecurityAttributes, long dwFlags, long lpScreenBufferData);
	long WINAPI SetConsoleActiveScreenBuffer(long hConsoleOutput);
	long GConsoleBuffer;
	int consoleInitialized = 0;
	int consolePrintTrue = 1;

	void consoleInit()
	{
		if(consoleInitialized) return;
		consoleInitialized = 1;
		AllocConsole();
		GConsoleBuffer = CreateConsoleScreenBuffer(GENERIC_WRITE, FILE_SHARE_READ, 0, CONSOLE_TEXTMODE_BUFFER, 0);
		SetConsoleActiveScreenBuffer(GConsoleBuffer);	
	}

	void cdiag(char* AText)
	{
		if(!consolePrintTrue) return;
		if(!consoleInitialized) consoleInit();
		WriteConsole(GConsoleBuffer, AText, str_len(AText), NULL, 0);	
	}
	
	#define cprintf0(str) cdiag(_chr(str))
	#define cprintf1(str,arg1) cdiag(_chr(str_printf(NULL,str,arg1)))
	#define cprintf2(str,arg1,arg2) cdiag(_chr(str_printf(NULL,str,arg1,arg2)))
	#define cprintf3(str,arg1,arg2,arg3) cdiag(_chr(str_printf(NULL,str,arg1,arg2,arg3)))
	#define cprintf4(str,arg1,arg2,arg3,arg4) cdiag(_chr(str_printf(NULL,str,arg1,arg2,arg3,arg4)))
	#define cprintf5(str,arg1,arg2,arg3,arg4,arg5) cdiag(_chr(str_printf(NULL,str,arg1,arg2,arg3,arg4,arg5)))
#endif



"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1