Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6373533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:22:33+00:00 2026-05-25T01:22:33+00:00

I have a common unit that does some logging to GExperts Debugger and/or OutputDebugString.

  • 0

I have a common unit that does some logging to GExperts Debugger and/or OutputDebugString. I am going to use it in a console app, so I want it to be able to output to stdout via writeln().
The main executable has {$APPTYPE CONSOLE} already, but I don’t think that’ll help me here. The logging routine will be called from several places:

  1. the main console app, which will link to a BPL,
  2. from another BPL that “requires” the first bpl, and…..
  3. from a DLL that statically links the unit.

The BPLs and DLL will be built with no visibility to the {$APPTYPE CONSOLE} directive, so I can’t use IFDEF conditional compilation. The BPL and DLL need to be able to go either way, depending whether the main app is a regular winapp or console app.

One ugly solution that occurred to me is to use the name of the executable. ex:

if (UpperCase(ExtractFileName(ParamStr(0))) = 'MYCONSOLEAPP.EXE')  then ...

But I hate to do that, as I could have other console apps…

I’d rather just have a magic function AmIAConsoleApp : boolean;
Is there anything like that?
I’m using Delphi2005 on this project.

Update: I see that I’m kind of a duplicate of this question, but I’d like to survey the Delphi folks to see if there’s a better approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:22:34+00:00Added an answer on May 25, 2026 at 1:22 am

    Call GetStdHandle(Std_Output_Handle). If it succeeds and returns zero, then there is no console to write to. Other return values indicate that a console is attached to the process, so you can write to it (although the console may not be the most desirable place to log messages in a console program since they’ll interfere with the normal output). Something like this:

    function IAmAConsoleApp: Boolean;
    var
      Stdout: THandle;
    begin
      Stdout := GetStdHandle(Std_Output_Handle);
      Win32Check(Stdout <> Invalid_Handle_Value);
      Result := Stdout <> 0;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have several common libs. Ideally we want them all to use the latest
i have several common elements (components), that will generate some html. it seems my
I have a project where there are multiple applications that have some common configuration
I have two unit tests that should share a lot of common tests with
I have some unit tests that run fine on my dev machine on both
I have some test classes that are making use of spring-batch, and hibernate. My
I want to create templates for base new reports on to have common designs.
I've got a method that does some IO that generally looks like this: public
I have some text coming into a database that apparently has some sort of
I was advised a while ago that is was common place to use std::vector

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.