winapi >> GetWindow - Infinite Loop?

by mayayana » Thu, 13 Mar 2008 07:25:36 GMT


> > Thanks. I never thought about that. Matthew
> > Curland showed a similar method for UserControls
> > to subclass themselves, but it hadn't occurred
> > to me that calling out to the .bas might be
> > required.
>
> I'd be interested in looking at that method by Matt. Do you recall, was
it in his
> book or one of his VBPJ columns?
>


It's in his book and a limited example was in
August 2001 VBPJ:
Black Belt Programming: Provide Pointers to Class Functions

If you have the book there are sample projects
on the CD, in PowerVB\Samples\CreateWindow.

If you have trouble finding it look for
"InitPushParamThunk". That's the name of a function
using inline assembly that's part of the very small
amount of code needed to set up any number of
UCs to subclass themselves and/or their consituent
controls. The whole thing was presented in his book
as a way to use owner-drawn windows that could
be wrapped in the convenience of VB by "anchoring"
them on a UC.

(I seem to remember a group discussion some time back
about this, so I went to check your site. I was just looking
at your HookMe sample, trying to figure out if that was a
similar approach, but so far I don't get it. You're using classes
to enable multiple subclasses? I've never seen GetProp and
SetProp before.)




winapi >> GetWindow - Infinite Loop?

by mayayana » Thu, 13 Mar 2008 22:49:36 GMT



Woops. Never mind all of that. While Matthew
Curland's code is interesting, and I'm glad I
found the HookMe sample, we were talking about
callbacks and I realized that I've wandered off into
my own private subclassing Idaho. :)

winapi >> GetWindow - Infinite Loop?

by Karl E. Peterson » Fri, 14 Mar 2008 02:51:28 GMT


I'll definitely take a closer look. Thanks.
--
.NET: It's About Trust!
http://vfred.mvps.org

winapi >> GetWindow - Infinite Loop?

by Karl E. Peterson » Fri, 14 Mar 2008 02:51:58 GMT


Something appealing about that. Can't say for sure what it may be. <g>
--
.NET: It's About Trust!
http://vfred.mvps.org

winapi >> GetWindow - Infinite Loop?

by Michael C » Wed, 19 Mar 2008 12:48:16 GMT


http://mikesdriveway.com/programming

and look at the sample "VB6 API callbacks without addressof"

BTW, to solve your problem you could add some code in to check for an
infinite loop and log the results. This would at least tell you if the
parent was it's own child or if there was a relationship with more than 1
window.

Michael

winapi >> GetWindow - Infinite Loop?

by Michael C » Wed, 19 Mar 2008 13:06:25 GMT


I know you'll know some or most of this but will explain it all for
everyone's benefit.

There could be 1 million instance of a class but there is only 1 function
shared by the 1 million instances that is always in the same location and
can be called via a callback. The function will never move in memory and
will not disappear if all the instances of a class are destroyed. I presume
the function exists before any classes are created. The real reason that
AddressOf doesn't work on class function is because it has 2 extra hidden
parameters, the ObjPtr param and the return value which is returned as a
byref param. The actual return value is the hResult which indicates to the
caller that an error occurred. As an example, a function in a class like
this:

public Function AddOne(ByVal Value As long) as Long

will actually look like this

public Function AddOne(ByVal ObjPointer As Long, ByVal Value as long, ByRef
ReturnValue as Long) as Long

The ObjPointer parameter simply indicates to the function what instance of
the class should be used to reference data. The reasons this can't be called
using AddressOf are fairly obvious but it would be possible for MS to
provide a proxy calling function but they didn't implement this.

The other interesting thing is the function wouldn't have to be private as
the private functions are in the vtable also, they're just at the end
(although this might only apply to PCode from what I remember).



No, Matt got around it by providing a proxy function in assembly code.

Michael

winapi >> GetWindow - Infinite Loop?

by Michael C » Wed, 19 Mar 2008 13:08:45 GMT


Accidentally pushed ctrl-enter before answering this one. AFAIK, class
instance are not moved around in memory. Anyone who used ObjPtr(Me) would be
in a lot of trouble if they did :-)

Michael

winapi >> GetWindow - Infinite Loop?

by Scott Seligman » Wed, 19 Mar 2008 13:51:11 GMT


Looks like the code's really at
http://mikesdriveway.com/code/

Using some machine code, he's creating a stub function in memory that
calls into the class function by cracking the vtable.

A little too hackish for my tastes, but I do give him points for a
clever method to solve the problem.

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
It has been said that democracy is the worst form of government
except all the others that have been tried.
-- Sir Winston Churchill

winapi >> GetWindow - Infinite Loop?

by Michael C » Wed, 19 Mar 2008 14:17:03 GMT


Good pickup. I thought I changed that before posting.


Yes.


If the language did support callbacks in a class it would do something
similar, although I do agree it is pretty hacky.

Michael