0 registered members (),
1,459
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Debugconsole(including printf override)
#415852
01/24/13 17:21
01/24/13 17:21
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
OP
Serious User
|
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:
#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 predeclaration before and the 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: 3dgs_snake]
#415882
01/25/13 08:17
01/25/13 08:17
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
OP
Serious User
|
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 (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
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Made some changes to it, now it's a little more usable IMO:
#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
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Or an alternative version which does "everything" on its own:
#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
|
|
|
|