Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OutputDebugStr() - how to see if it is going anywhere?

151 views
Skip to first unread message

Bill Davy

unread,
Aug 22, 2008, 10:40:43 AM8/22/08
to
Because if not, I'd like to capture the output and append to a log file.
How can I find out about my program's runtime environment in this respect?

TIA
Bill


Victor Bazarov

unread,
Aug 22, 2008, 11:06:02 AM8/22/08
to
Bill Davy wrote:
> Because if not,

Because if not what? Your question is "how", and the answer is "run
your program under a debugger, it will capture the output".

> I'd like to capture the output and append to a log file.

You can't do that unless you write a debugger (and use the debug API
available, see MSDN) and run your program under it.

> How can I find out about my program's runtime environment in this respect?

In what respect? If you need a non debugger driven program to output
some information only in debug mode, use

#ifdef _DEBUG
myDebugLog << "blah";
#endif

in your code.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Bill Davy

unread,
Aug 22, 2008, 11:19:31 AM8/22/08
to
"Victor Bazarov" <v.Aba...@comAcast.net> wrote in message
news:g8mkl3$a47$1...@news.datemas.de...

> Bill Davy wrote:
>> Because if not,
>
> Because if not what? Your question is "how", and the answer is "run your
> program under a debugger, it will capture the output".
>
> > I'd like to capture the output and append to a log file.
>
> You can't do that unless you write a debugger (and use the debug API
> available, see MSDN) and run your program under it.
>
>> How can I find out about my program's runtime environment in this
>> respect?

RUNTIME

>
> In what respect? If you need a non debugger driven program to output some
> information only in debug mode, use
>
> #ifdef _DEBUG
> myDebugLog << "blah";
> #endif

COMPILE TIME

Victor Bazarov

unread,
Aug 22, 2008, 11:35:22 AM8/22/08
to
Bill Davy wrote:
> "Victor Bazarov" <v.Aba...@comAcast.net> wrote in message
> news:g8mkl3$a47$1...@news.datemas.de...
>> Bill Davy wrote:
>>> Because if not,
>> Because if not what? Your question is "how", and the answer is "run your
>> program under a debugger, it will capture the output".
>>
>>> I'd like to capture the output and append to a log file.
>> You can't do that unless you write a debugger (and use the debug API
>> available, see MSDN) and run your program under it.
>>
>>> How can I find out about my program's runtime environment in this
>>> respect?
>
> RUNTIME
>
>> In what respect? If you need a non debugger driven program to output some
>> information only in debug mode, use
>>
>> #ifdef _DEBUG
>> myDebugLog << "blah";
>> #endif
>
> COMPILE TIME
>
>> in your code.

<shrug> You might consider being a bit more verbose. Do you want your
program to know whether it's running under a debugger and behave
differently if it is?

Bill Davy

unread,
Aug 22, 2008, 11:40:55 AM8/22/08
to
"Victor Bazarov" <v.Aba...@comAcast.net> wrote in message
news:g8mmbs$dg6$1...@news.datemas.de...

Yes.
Or, if you prefer, that's an affirmative response.

Bill


Victor Bazarov

unread,
Aug 22, 2008, 11:54:02 AM8/22/08
to

Then I do not know the answer. Ask in 'microsoft.public.vc.language',
but don't hold your breath. If I had to guess, you probably could try
enumerating all processes in the system and find out which one is the
parent process of yours. But then it's questionable what would happen
if you 'attach' the debugger instead of starting your process in one...

My next question is, *why* do you think you *need* that? Protection
from cracking? Perhaps other ways to accomplish what you need without
finding out whether you're running under a debugger...

Pavel A.

unread,
Aug 22, 2008, 1:16:50 PM8/22/08
to
Bill Davy wrote:
> Because if not, I'd like to capture the output and append to a log file.
> How can I find out about my program's runtime environment in this respect?
>

Get this little wonderful program, it will show all the ODS()
spew of your app, and log to a file, too.
http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

--PA


Alex Blekhman

unread,
Aug 22, 2008, 1:56:18 PM8/22/08
to
"Bill Davy" wrote:
> How can I find out about my program's runtime environment in
> this respect?

In addition to Pavel's answer. You can detect whether the process
is under a debugger with `IsDebuggerPresent' API function.

HTH
Alex


Pavel A.

unread,
Aug 22, 2008, 2:06:44 PM8/22/08
to

Ah. Now I understand what the OP wants.
Then, IsDebuggerPresent gives exactly that: tells you whether a debugger
is attached to your app. But even if not, debug spew can still show up
elsewhere: DebugView is not a debugger, nevertheless, it will show the
spew. OTOH, a real debugger may ignore the spew.

So if the OP really needs to know if somebody is listening, in runtime,
he has to roll his own...
or, maybe, look at EWT (aka "WMI trace"), it comes with it's own
control interface.

Regards,
--PA

Bill Davy

unread,
Sep 1, 2008, 4:04:40 AM9/1/08
to
"Pavel A." <pav...@NOfastmailNO.fm> wrote in message
news:OQStMIIB...@TK2MSFTNGP03.phx.gbl...


Many thanks to all for their comments.
I think I have enough to be getting on with.

FWIW, I share the view of someone who said turning off ASSERT in the release
version is like taking off the lifebelt when you go out to sea. I feel much
the same about log output, at least during initial deployment.

Rgds,
Bill


Pavel A.

unread,
Sep 1, 2008, 7:06:52 AM9/1/08
to
Bill Davy wrote:
..........

> FWIW, I share the view of someone who said turning off ASSERT in the release
> version is like taking off the lifebelt when you go out to sea. I feel much
> the same about log output, at least during initial deployment.

Nevertheless, the assert/ASSERT macro is documented to take action
only in debug build.
Usually people define another set of checks and prints/traces
to stay in release builds.
Also, debug APIs like ODS() have some security and stability issues,
so make sure these are disabled by default.

--PA

0 new messages