🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14152

Re: Windows wierdness (SendMessage, Win98, Win2000) repeat

#14152
From: Keith
Date: Sat, 30 Aug 2003 15:17
77 lines
3360 bytes

David wrote:

> A couple weeks ago I posted about a strange problem with almost the same title.  Out of town
> since then, but still cannot see what is happening.  The program crashes on Win98, but not
> 2000 or ME.  If anyone has time to look at it I am posting it at the following location:
>
> http://www.randommonkeyworks.com/Programming/Problem/Problem_Overview.html
>
> It is a little more than 50 lines, therefore I am not posting entire thing here.
>
> Thanks,
> David

Yes sir, here's why:

void WinComboBox::add(char * str) {
   SendMessage(hwndC, CB_ADDSTRING, 0, (LPARAM) str);
}

In the call to SendMessage, you are actually getting a call to SendMessageA.  The four
parameters are not being removed from the stack prior to returning to the caller at line:

cBoxC.add("A");  <<-----------this line produces the call (of course)

and here is the .add method code:

push ebp
mov ebp,esp    ; standard function entry to establish addressibility of stack params.

push dword ptr[ebp+0x0c]   ;  push lparam str
push 0            ; push your 3rd param
push 0x143    ; push CB_ADDSTRING
mov eax,[ebp+0x08] ; obtain address to owner of hwndC
push dword ptr [eax+0x2c] ; push hwndC at offset 2c into owner of hwndC
call USER32.SendMessageA

; note that no parameters are removed from stack at this point
; also note that USER32.SendMessageA did NOT remove the parameters from the stack

pop ebp ; restore entry point addressibility ; (caused the stack frame reference to be lost)
ret ; return to caller (return to incorrect address)


You can observe all this by setting a single breakpoint on:

void WinComboBox::add(char * str) {

and when the breakpoint is hit, view the CPU window.

I suppose that the 'kind' of call to SendMessage(.....) needs to be modified so that the caller
removes the pushed parameters, and not to expect the called SendMessage to remove the
parameters.

keith









TJunkForm::TJunkForm() :
            WinBlankForm(NULL, 0, 0, 400, 400,
                        (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW) &
                        ~WS_SIZEBOX & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX),
            cBoxC(this, 0, 0, clientWidth(), 250) {

   ShowWindow(hwndC, SW_SHOW);
   UpdateWindow(hwndC);
   for (int i=0; i<16; ++i)
               cBoxC.add("A");  <<-----------this line produces the call
   cBoxC.itemIndex(0);
}
Technical Details
Message-ID: <3F50C002.901B2CC9@sbcglobal.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3F50A23C.1090706@anonymous_one.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,d5c2d7b43b5c1d37
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-30 08:21:14 PST
Message-ID: <3F50C002.901B2CC9@sbcglobal.net>
Date: Sat, 30 Aug 2003 10:17:22 -0500
From: Keith <kdopson@sbcglobal.net>
X-Mailer: Mozilla 4.79 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Windows wierdness (SendMessage, Win98, Win2000) repeat
References: <3F50A23C.1090706@anonymous_one.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 65.71.227.85
X-Trace: newsgroups.borland.com 1062256641 65.71.227.85 (30 Aug 2003 08:17:21 -0700)
Lines: 80
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail