Win32 console output

I'm trying to write a simple console output app under Windows XP and having no luck. The WriteConsole procedure wants a handle to the console screen buffer but I can't seem to get one. CreateConsoleScreenBuffer just gives an invalid handle error when I run it (with parameters GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL) so I tried GetStdHandle with the STD_OUTPUT_HANDLE parameter, which doesn't return an error but doesn't give me a handle either. The following is the section of code (compiled with MASM 6.14 and linked with MS incremental linker 5.12). Oh and it's the first thing to run.

; get stdout handle
push STD_OUTPUT_HANDLE
call GetStdHandle
; eax is now 0

Anybody know why this is happening/how to do it properly?
--Rob
LVL 6
boycyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

boycyAuthor Commented:
Ok, bit more info. Reading through the documentation for GetStdHandle again (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getstdhandle.asp) I think the problem is that NULL is being returned because my program doesn't have any associated standard handles. So...how do I get my program to have standard handles? I remember reading that under windows, a bit in the PE header states whether the app is console or windowed...but how can I change this from the assembly source?
0
boycyAuthor Commented:
Right, managed to answer it myself - finally!
For those interested, the first thing that 'worked' was calling AllocConsole before attempting to retrieve the stdout handle, the only problem was that opened up a new command prompt and closed it as soon as ExitProcess was called.
The bit that did it for me was passing /subsystem:console instead of /subsystem:windows to the linker :D
0
ee_ai_constructCommented:
Question answered by asker or dialog deemed valuable.
Closed, 100 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Assembly

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.