Link to home
Start Free TrialLog in
Avatar of ChrisDrake
ChrisDrake

asked on

How can I print color text under "cmd.exe" in windows XP

I've tried putting ansi.sys into config.nt, but later discovered that this is not relevant to "cmd.exe" (and obviously, ansi escape sequences don't just work without something to handle them).

I've tried writing a driver to call int 10h, but this blows up on the int 10h call with the following error:-
    Unhandled exception ...: 0xC0000005: Access Violation.

I don't recall an INT21 interface for changing color. I can't find any hints in MSVC++ help, nor google.

I know cmd.exe can *do* color, since after dropping into NTVDM and doing color there, it returns and retains the color on the cmd.exe's screen (and the cmd.exe's output overwrites both the residual outputted text as well as the color attributes, so whatever output routine cmd.exe is using, it's programmed to *do* colour it seems; and of course you can set everything to colors other than black+white (see cmd.exe /?)... it's just not clear how to have colored output!)
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ChrisDrake
ChrisDrake

ASKER

Awesome!  I *can't* beleive how long I spent both in Google *and* MSDN trying to hunt this down... It was of course there all the time; but as with almost all Microsoft technologies, if you don't know the obscure words/phrases MS have dreamed up for the concept (in this case - it was "SetConsoleTextAttribute()" ), you've got no chance of hunting it down.

Anyways - I wrote me my own shiny new ANSI to SetConsoleTextAttribute() converting driver, and I'm happy-as now :-)