[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

BeeJ

12/3/2011 2:21:00 AM

So I added more code in the UC that uses subclassing and the
subclassing is now failing again.

Is there some limit to how much code can be in the UC?

Limit to the number of Property subs?

Some other limit.

Something in the subclassing setup that need to be "enlarged"?

Hints please.


13 Answers

Mayayana

12/3/2011 3:19:00 PM

0

That's not much to go on. The Paul Caton subclass?
You didn't change the WindowProc position? No change
to the subclass class *at all*? Maybe funky code added
to the WindowProc?

Did you know there's also a short version called simple
subclass?

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=73803&am...

It uses the formerly undocumented
subclassing functions that Karl P. has talked about. (He
has sample code at his site.) As I understand it, Microsoft
was forced to publish a number of functions that they
had kept secret, anti-competitively. If you look up
SetWindowSubclass and RemoveWindowSubclass you'll find
that MSDN says they're XP and later only. I doubt that's
true. Microsoft stopped being honest about that awhile back.
They always claim now that functions are only usable on
the last Windows version that *they are officially supporting*.
I guess that way they can say they're not technically lying;
they just "officially" don't remember anything that happened
before XP.

In any case, it might be worth a try if you can't get the
other version working. Just test it on 98/2000/ME if you
expect to support those. I haven't tried it myself. Nor have
I tried Karl's code. While Paul Caton's original code is not
very compact, I've found it to be *very* dependable. I
use a dozen or more SSUCs in some cases; as easily as
if they were part of the "intrinsic toolbox".


| So I added more code in the UC that uses subclassing and the
| subclassing is now failing again.
|
| Is there some limit to how much code can be in the UC?
|
| Limit to the number of Property subs?
|
| Some other limit.
|
| Something in the subclassing setup that need to be "enlarged"?
|
| Hints please.
|
|


ralph

12/3/2011 5:20:00 PM

0

On Fri, 02 Dec 2011 18:21:00 -0800, BeeJ <nospam@spamnot.com> wrote:

>So I added more code in the UC that uses subclassing and the
>subclassing is now failing again.
>
>Is there some limit to how much code can be in the UC?
>
>Limit to the number of Property subs?
>
>Some other limit.
>
>Something in the subclassing setup that need to be "enlarged"?
>
>Hints please.
>

Assuming "now failing again" means the control is no longer responding
to Windows Messages? The most common reason for this is failing to
replace the subclassed WindProc with the original WinProc.

If it is failing to catch messages in the subclassed WindProc, yet is
still receiving messages from the original WinProc, then you have
probably subclassed the wrong WindProc (or rather an invalid address).

That is, essentially the same thing for either problem. You are no
longer chewing on what you think you are.

Take a look at the following article.
http://www.vbaccelerator.com/home/vb/code/libraries/subclassing/SSubTimer/a...
While it discusses the situation of how two instances of a control can
become confused, the basic cause is the same for any situation where a
subclassed control appears to stop responding. (And for a sudden rash
of GPFs.)

There are limits to how much code can be in a VB module. Such things
as total lines, the number of constants, number of properties, etc.
However, these constraints normally result in compile time errors, not
in hidden runtime errors.

-ralph

BeeJ

12/4/2011 11:45:00 PM

0

No, as before, it will not initialize.
It cannot find the callback point.

from here it calls sc_Subclass
With UserControl
'Subclass the UserControl
bSuccess = sc_Subclass(.hWnd)

in sc_subclass() it fails here
nAddr = zAddressOf(oCallback, nOrdinal)
' Get the address of the specified ordinal method

oCallback is the UserControl.hWnd

And no, there is no code past the cliff as mandated.
So maybe the UC is too large? Or has too many Public access points?
Not sure how this all works.
I have look for a place where some limit might be exceed and so far
have not found anything ... yet.



--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

BeeJ

12/4/2011 11:51:00 PM

0

Hope this is the "protected" verison supposedly like the Canton one
that tries to avoid crashing everything when I screw up. Yeah I know,
but I screw up.
Even when I am not using subclassing, I managed to edit myself into a
hole and crash the IDE. Run --> Edit --> crash and loose my edits
while running; so I have to stop more often than I want to save and
restart the whole process over. Sort of getting used to it.



--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

Mayayana

12/5/2011 2:32:00 AM

0

| No, as before, it will not initialize.
| It cannot find the callback point.
|
| from here it calls sc_Subclass
| With UserControl
| 'Subclass the UserControl
| bSuccess = sc_Subclass(.hWnd)
|
| in sc_subclass() it fails here
| nAddr = zAddressOf(oCallback, nOrdinal)
| ' Get the address of the specified ordinal method
|
| oCallback is the UserControl.hWnd
|

Maybe I'm missing something, but I don't see how oCallback
is the UC. If you don't specify it then oCallback is the
subclassing class.
Typically you would be calling startup code from
UserControl_ReadProperties (or maybe UserControl_InitProperties?)
that calls the subclassing class *from there*
with something like:

sc_Subclass(userControl.hWnd, , 1, Me)

That would set the last function in the
UC (which must be Friend) as the windowproc.
The hWnd parameter is the window to be
subclassed, which is not the same as the location
of the windowproc function.


Then....

AddMsg hWnd, WM_SOMETHING, Before/after

At close...

DelMsg hWnd, WM_SOMETHING, Before/after

Finally...

UnSubclass hWnd, Me



BeeJ

12/5/2011 3:17:00 AM

0

See below and
this all works if I take out code in the UC.
and it all worked before I added code.
added a few more small subs in the UC
added a few Let Get in the UC

the code all compiles and runs fine except the subclassing of the mouse
events is simply non-functional and no errors thrown.

I have another app that it works perfectly in but the UC is smaller.

So wondering about UC size or ???
Looking at the Peterson code and the planet source previously posted
makes me think it is a size problem since that code talks about
increasing the VTable lookup distance. Does not go into details but
maybe the entry point is further down the table now. Not sure I am
qualified to fiddle with that. lol


Mayayana wrote on 12/4/2011 :
>> No, as before, it will not initialize.
>> It cannot find the callback point.
>>
>> from here it calls sc_Subclass
>> With UserControl
>> 'Subclass the UserControl
>> bSuccess = sc_Subclass(.hWnd)
>>
>> in sc_subclass() it fails here
>> nAddr = zAddressOf(oCallback, nOrdinal)
>> ' Get the address of the specified ordinal method
>>
>> oCallback is the UserControl.hWnd
>>
>
> Maybe I'm missing something, but I don't see how oCallback
> is the UC. If you don't specify it then oCallback is the
> subclassing class.

passed as Me within the UC

> Typically you would be calling startup code from
> UserControl_ReadProperties (or maybe UserControl_InitProperties?)
> that calls the subclassing class *from there*
> with something like:
>
> sc_Subclass(userControl.hWnd, , 1, Me)
>
> That would set the last function in the
> UC (which must be Friend) as the windowproc.
> The hWnd parameter is the window to be
> subclassed, which is not the same as the location
> of the windowproc function.
>

All done within the UC. No classes like Perterson.

> Then....
>
> AddMsg hWnd, WM_SOMETHING, Before/after
>
> At close...
>
> DelMsg hWnd, WM_SOMETHING, Before/after
>
> Finally...
>
> UnSubclass hWnd, Me

ain't this fun!


Norm Cook

12/5/2011 12:10:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jbh11l$2ess$1@adenine.netfront.net...
> Hope this is the "protected" verison supposedly like the Canton one that
> tries to avoid crashing everything when I screw up. Yeah I know, but I
> screw up.
> Even when I am not using subclassing, I managed to edit myself into a hole
> and crash the IDE. Run --> Edit --> crash and loose my edits while
> running; so I have to stop more often than I want to save and restart the
> whole process over. Sort of getting used to it.
>
>
>
> --- Posted via news://freenews.netfront.net/ - Complaints to
> news@netfront.net ---

Anytime I use subclassing:

Tools|Options|Environment
When a program starts: Save Changes


Mayayana

12/5/2011 2:13:00 PM

0


nAddr = zAddressOf(oCallback, nOrdinal) is from Caton's
subclassing class, yet your other code snippets and info.
seem to imply that you're using his simple subclass. It might
make it easier for everyone if you were more clear and
informative about what you're doing at the start.


| makes me think it is a size problem since that code talks about
| increasing the VTable lookup distance. Does not go into details but
| maybe the entry point is further down the table now. Not sure I am
| qualified to fiddle with that. lol

Assuming that you're using the simple subclassing
and haven't mashed together the 2 code samples...

The sc_Subclass code is scanning up to 512 addresses
until it finds an invaild one. It then backs up 4 bytes
and assumes that's your windowproc -- the last private
function in the module. (Please say you don't have 512
functions/properties. :) Caton also made an interesting
comment on the download page about public variables
messing things up. ....Part of the reason I don't use that
simple subclass code is because he's no longer really
doing VB. He posted a quick fix for XP that may or may
not be stable. ...In any case, I'm still trying to figure out
how you're calling zAddressOf, since that's nowhere in the
Caton simple subclass code, and the code where he does use
it is a separate class.




BeeJ

12/5/2011 11:16:00 PM

0

I can post the subs but not sure how much ... see below

I revisited the previous "fix" that worked.

So again I commented out two Property Let/Get pairs and is started
working again. All this code is error free in that it all runs except
for the subclass aspect.
So I uncommented and went into the subclassing routine and increaed the
vTable search nlimit depth from 32 in steps up to 512. Canton uses a
different search algo. That supposedly probes at class, form and UC.
No luck with that.

Sorry about the line wraps.

<snip beg>
If oCallback Is Nothing Then
' If the user hasn't specified the callback owner
Set oCallback = Me ' IN THE UC
' Then it is me
End If

nAddr = zAddressOf(oCallback, nOrdinal)
' Get the address of the specified ordinal method
If nAddr = 0 Then ' RETURNS ZERO == FAILURE
<snip end>

' ===============================
Private Function zAddressOf(ByVal oCallback As Object, ByVal nOrdinal
As Long) As Long

' Return the address of the specified ordinal method on the
oCallback object, 1 = last private method, 2 = second last private
method, etc

Dim bSub As Byte
'Value we expect to find pointed at by a vTable method entry
Dim bVal As Byte
Dim nAddr As Long
'Address of the vTable
Dim i As Long
'Loop index
Dim j As Long
'Loop limit

RtlMoveMemory VarPtr(nAddr), ObjPtr(oCallback), 4
'Get the address of the callback object's instance
If Not zProbe(nAddr + &H1C, i, bSub) Then
'Probe for a Class method
If Not zProbe(nAddr + &H6F8, i, bSub) Then
'Probe for a Form method
If Not zProbe(nAddr + &H7A4, i, bSub) Then
'Probe for a UserControl method
Exit Function
'Bail...
End If
End If
End If

i = i + 4
'Bump to the next entry
j = i + 1024
'Set a reasonable limit, scan 256 vTable entries
Do While i < j
RtlMoveMemory VarPtr(nAddr), i, 4
'Get the address stored in this vTable entry

If IsBadCodePtr(nAddr) Then
'Is the entry an invalid code address?
RtlMoveMemory VarPtr(zAddressOf), i - (nOrdinal * 4), 4
'Return the specified vTable entry address
Exit Do
'Bad method signature, quit loop
End If

RtlMoveMemory VarPtr(bVal), nAddr, 1
'Get the byte pointed to by the vTable entry
If bVal <> bSub Then
'If the byte doesn't match the expected value...
RtlMoveMemory VarPtr(zAddressOf), i - (nOrdinal * 4), 4
'Return the specified vTable entry address
Exit Do
'Bad method signature, quit loop
End If

i = i + 4
'Next vTable entry
Loop

End Function 'zAddressOf

' ===============================

Private Function zProbe(ByVal nStart As Long, ByRef nMethod As Long,
ByRef bSub As Byte) As Boolean

'Probe at the specified start address for a method signature

Dim bVal As Byte
Dim nAddr As Long
Dim nLimit As Long
Dim nEntry As Long

nAddr = nStart
'Start address
nLimit = nAddr + 32
'Probe eight entries
Do While nAddr < nLimit
'While we've not reached our probe depth
RtlMoveMemory VarPtr(nEntry), nAddr, 4
'Get the vTable entry

If nEntry <> 0 Then
'If not an implemented interface
RtlMoveMemory VarPtr(bVal), nEntry, 1
'Get the value pointed at by the vTable entry
If bVal = &H33 Or bVal = &HE9 Then
'Check for a native or pcode method signature
nMethod = nAddr
'Store the vTable entry
bSub = bVal
'Store the found method signature
zProbe = True
'Indicate success
Exit Function
'Return
End If
End If

nAddr = nAddr + 4
'Next vTable entry
Loop

End Function 'zProbe


BeeJ

12/5/2011 11:27:00 PM

0

Norm Cook wrote :
> "BeeJ" <nospam@spamnot.com> wrote in message
> news:jbh11l$2ess$1@adenine.netfront.net...
>> Hope this is the "protected" verison supposedly like the Canton one that
>> tries to avoid crashing everything when I screw up. Yeah I know, but I
>> screw up.
>> Even when I am not using subclassing, I managed to edit myself into a hole
>> and crash the IDE. Run --> Edit --> crash and loose my edits while
>> running; so I have to stop more often than I want to save and restart the
>> whole process over. Sort of getting used to it.
>>
>>
>>
>> --- Posted via news://freenews.netfront.net/ - Complaints to
>> news@netfront.net ---
>
> Anytime I use subclassing:
>
> Tools|Options|Environment
> When a program starts: Save Changes

I use that but that does not help when
running --> pause --> edit --> crash.
All these edits are lost and my brain has to go into a loop that makes
a another groove.



--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---