Don't know your problem with this Topic. I got it to run a little bit.
I required 4 function from the windows Api:
-AllocConsole
-GetStdHandle this one twice for in and output
-WriteConsole writing into the console
-ReadConsole reading from the console
Sadly i had some problems with the chars.
but i could write something to the console and read something from the console. If you want this running without stopping the game. I think you must put this into an extra thread( the read-funktion returns only if in the console Enter is pressed)

I think you want to see my solution. Here it is:
Click to reveal..

console.h
Code:
/// loading some required functions not defined in windows.h 

BOOL WINAPI WriteConsole( HANDLE , const VOID* , DWORD , LPDWORD , LPVOID );
#define PRAGMA_API WriteConsole;kernel32!WriteConsoleA

BOOL WINAPI ReadConsole(HANDLE ,LPVOID ,DWORD ,LPDWORD ,LPVOID );
#define PRAGMA_API ReadConsole;kernel32!ReadConsoleA


console.c
Code:
///////////////////////////////
#include <acknex.h>
#include <windows.h>
#include "console.h"
///////////////////////////////

#define PRAGMA_POINTER

HANDLE c_out = 0;
HANDLE c_in  = 0;


function main()
{
	video_screen = 0;
	wait(1);
	
	/// allocating console
	AllocConsole();
	SetConsoleTitle("Acknex Console");
	
	/// prepare in output
	c_out = GetStdHandle( STD_OUTPUT_HANDLE );
	c_in  = GetStdHandle( STD_INPUT_HANDLE  );
	if( !c_out ) printf( "no output" );
	if( !c_in ) printf( "no input" );
	
	DWORD written = 0;
	DWORD read = 0;
	char* in_buffer;
	char prep_buff[128];
	
	
	WriteConsole( c_out, "Console Entered\n", 16 , &written , NULL );
	
	/// polling input
	while(!key_esc)
	{
		ReadConsole( c_in , in_buffer , 128 , &read , NULL );
		if( read > 0 )
		{
			memset((void*)&prep_buff,0,sizeof(prep_buff)); // safety for nulling the prepbuffer
			DWORD i;
			for( i = 0 ; i < 128 ; i++ )
			{
				if( i < read  )
				{
					prep_buff[i] = in_buffer[i]; // copy chars
				}
				else
				{
					prep_buff[i] = 0;  // fill the rest with 0
				}
			}
			/// print to acknex 
			printf("Eingabe: ");
			printf(prep_buff);
			/// print to console
			WriteConsole( c_out, "Eingabe: ", 9 , &written , NULL );
			WriteConsole( c_out, in_buffer, read , &written , NULL ); /// works great
			//WriteConsole( c_out, prep_buff, read , &written , NULL ); /// for some stupid unknown reason prints nonsesnse
			WriteConsole( c_out, "\n", 1 , &written , NULL );
			
		}
		wait(1); // let acknex do its stuff.
	}
	
	FreeConsole();
	sys_exit(NULL);
}




Hope my Code could help anybody.

EDIT: I should read the hole threads including the links. So someone was faster with the code which is i think also nicer(at least i haven't copy and pasted the code from somewhere)

muffel

Last edited by muffel; 10/26/10 09:08.