ATL Service as Console Application 
Author Message
 ATL Service as Console Application

Hello!

I want to provide ability to run my service from command prompt in debug
mode, and print debug messages to console.
Is there some ways to make ATL Service as Win32 console application?

--
With best regards,
Oleg Malkov.
--

Mordovian State University                    System Administrator
Internet Center


Phone/Fax: +7 (83422) 4-72-42



Sun, 27 Oct 2002 03:00:00 GMT  
 ATL Service as Console Application
ATL requires resources and those are unavailable to a console
application (you can't get your HINSTANCE). However, if you just
want to print to the console, there's Console API for that. Look up
AllocConsole() and friends.

This is the code I'm using in one of my projects:

=====================================
 if (::AllocConsole()) {
  int hCrt;
  FILE *hf;
  COORD Coords = {80, 2000};

  ::SetConsoleTitle(_T("Debug Console"));
  ::SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),  Coords);

  hCrt = _open_osfhandle((long) GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
  hf = _fdopen( hCrt, "w" );
  *stdout = *hf;
  setvbuf(stdout, NULL, _IONBF, 0);
 }
=====================================

I vaguely remember it came from some KB article...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Hello!

> I want to provide ability to run my service from command prompt in debug
> mode, and print debug messages to console.
> Is there some ways to make ATL Service as Win32 console application?

> --
> With best regards,
> Oleg Malkov.
> --

> Mordovian State University                    System Administrator
> Internet Center


> Phone/Fax: +7 (83422) 4-72-42



Sun, 27 Oct 2002 03:00:00 GMT  
 ATL Service as Console Application
Actually I had written a console wrapper which could redirect your stdio
calls (like printf and cout) to a console. Check out codeguru.developer.com.
That class might still be there.


Quote:
> ATL requires resources and those are unavailable to a console
> application (you can't get your HINSTANCE). However, if you just
> want to print to the console, there's Console API for that. Look up
> AllocConsole() and friends.

> This is the code I'm using in one of my projects:

> =====================================
>  if (::AllocConsole()) {
>   int hCrt;
>   FILE *hf;
>   COORD Coords = {80, 2000};

>   ::SetConsoleTitle(_T("Debug Console"));
>   ::SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),  Coords);

>   hCrt = _open_osfhandle((long) GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
>   hf = _fdopen( hCrt, "w" );
>   *stdout = *hf;
>   setvbuf(stdout, NULL, _IONBF, 0);
>  }
> =====================================

> I vaguely remember it came from some KB article...

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



> > Hello!

> > I want to provide ability to run my service from command prompt in debug
> > mode, and print debug messages to console.
> > Is there some ways to make ATL Service as Win32 console application?

> > --
> > With best regards,
> > Oleg Malkov.
> > --

> > Mordovian State University                    System Administrator
> > Internet Center


> > Phone/Fax: +7 (83422) 4-72-42



Tue, 29 Oct 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. how to use a console window in a win32 application..-- not console application

2. Launching A Console Application As An NT Service

3. Console Applications ran from service have default icons???

4. NT4.0 Service using console application

5. trouble getting a console based application to run hidden within a win32 service

6. ATL Server - Web Application/Web Service

7. Executing a console application without it opening a console

8. Starting a console application without the console window

9. Console control in console application

10. console application pauses when mouse clicks inside the console

11. Console o/p from windows application (not in new console)

12. Help creating a simple service using ATL Service

 

 
Powered by phpBB® Forum Software