🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Several ways to define 2 system-wide hotkeys, without to install keyboard-hook..

#8097
From: Remy Lebeau (TeamB)
Date: Mon, 22 Nov 2004 18:58
65 lines
3491 bytes
"Oren Halvani" <Spam@Me-Please.com> wrote in message
news:41a066cc@newsgroups.borland.com...

> Remy, i've found the following delphi code on the net..
>
> i've tried to convert it to c++ code (see bottom) but the
> compiler didn't recognized FreeMem( )...what does
> FreeMem do..?

It does what its name suggests - it frees the memory that was allocated by
GetMem().

> how can i rewrite it to c++ ?

    //  List all Windows with a Button on the taskbar...

    AnsiString __fastcall GetText(HWND Wnd)
    {
        AnsiString Result;

        int textlength = SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
        if( textlength > 0 )
        {
            Result.SetLength(textlength);
            SendMessage(Wnd, WM_GETTEXT, textlength,
reinterpret_cast<LPARAM>(Result.c_str()));
        }

        return Result;
    }

    BOOL CALLBACK EnumWindowsProc(HWND Wnd, LPARAM lParam)
    {
        if( (IsWindowVisible(Wnd) || IsIconic(Wnd)) &&
            ((GetWindowLong(Wnd, GWL_HWNDPARENT) == 0) ||
            (GetWindowLong(Wnd, GWL_HWNDPARENT) == GetDesktopWindow())) &&
            ((GetWindowLong(Wnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) == 0) )
            Form1->ListBox1->Items->Add("Handle: " + IntToStr(Wnd) + ",Text:
" + GetText(Wnd));
        return TRUE;
    }

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        EnumWindows(EnumWindowsProc, 0);
    }


>     sizeof(Text, textlength + 1);

That was a completely wrong translation of GetMem().  As its name suggests,
GetMem() allocates a block of memory.  sizeof(), on the other hand, merely
returns the byte size of the value passed to it.

>     return Text;
>     FreeMem(Text); // ???

You cannot call FreeMem() after a 'return' statement.  As soon as the
'return' statement executes, the function exists immediately and is no
longer running.  You have to call FreeMem() before you call 'return', or
else the memory is leaked.


Gambit
Technical Details
Message-ID: <41a23648$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <419ceea1@newsgroups.borland.com> <419cf173$1@newsgroups.borland.com> <419d2c69$1@newsgroups.borland.com> <419d3e01$1@newsgroups.borland.com> <419d8ce4@newsgroups.borland.com> <419dc340@newsgroups.borland.com> <419e5561$1@newsgroups.borland.com> <419e5ecc$1@newsgroups.borland.com> <419e6631@newsgroups.borland.com> <419e7adc$1@newsgroups.borland.com> <419e831e$1@newsgroups.borland.com> <419f0334$1@newsgroups.borland.com> <419f08b1@newsgroups.borland.com> <419fb061$1@newsgroups.borland.com> <419fc5aa@newsgroups.borland.com> <41a03fb6@newsgroups.borland.com> <41a066cc@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9a94ec9a8ef193c6
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <419ceea1@newsgroups.borland.com> <419cf173$1@newsgroups.borland.com> <419d2c69$1@newsgroups.borland.com> <419d3e01$1@newsgroups.borland.com> <419d8ce4@newsgroups.borland.com> <419dc340@newsgroups.borland.com> <419e5561$1@newsgroups.borland.com> <419e5ecc$1@newsgroups.borland.com> <419e6631@newsgroups.borland.com> <419e7adc$1@newsgroups.borland.com> <419e831e$1@newsgroups.borland.com> <419f0334$1@newsgroups.borland.com> <419f08b1@newsgroups.borland.com> <419fb061$1@newsgroups.borland.com> <419fc5aa@newsgroups.borland.com> <41a03fb6@newsgroups.borland.com> <41a066cc@newsgroups.borland.com>
Subject: Re: Several ways to define 2 system-wide hotkeys, without to install keyboard-hook..
Date: Mon, 22 Nov 2004 10:58:11 -0800
Lines: 67
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <41a23648$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101149768 68.69.17.41 (22 Nov 2004 10:56:08 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail