Re: Writing simple profiler

From: Robert Wessel (spamtrap_at_crayne.org)
Date: 09/22/04


Date: Wed, 22 Sep 2004 20:06:52 +0000 (UTC)


"Glen Able" <spamtrap@crayne.org> wrote in message news:<cirdbg$20k$1$8302bc10@news.demon.co.uk>...
> Oddly, my windows SDK seems to be completely ignorant of the 'OpenThread'
> function used here:
>
> > if (!hthread)
> > hthread = OpenThread(THREAD_ALL_ACCESS, 0, GetCurrentThreadId());
>
> I've tried replacing it with the following:
>
> if (!hthread)
> {
> // get current thread pseudohandle
> HANDLE pseudoHandle = GetCurrentThread();
>
> // convert to proper handle
> DuplicateHandle(GetCurrentProcess(),
> pseudoHandle,
> GetCurrentProcess(),
> &hthread,
> 0,
> false,
> DUPLICATE_SAME_ACCESS);
> }
>
>
> But then the callback always has the strange value of 0x77f8915e for eip,
> whereas the app is in the 0x00400000 kind of range.
>
> Any ideas?

Yep, you're using an SDK that's pre-Win2K, or has been configured that
way. The function should be defined in winbase.h, make sure it's in
your copy. You might check that you're not using an option that
prevents this building (for example, you're probably not going to have
this accessible if you've declared WINVER=0x400). I think if you've
set Win9x or NT4 compatibility you'd get the same effect.

GetCurrentThread will not work. It returns a pseudo-handle that
always addresses the currently running thread, not a handle specific
to the thread that called GetCurrentThread. It's actually kind of
surprising you don't just hang, since the first thing the callback
will do is suspend the thread it's running on!