🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Function Address Help

#8201
From: Remy Lebeau (TeamB)
Date: Mon, 15 Nov 2004 18:09
47 lines
3223 bytes
"Alistair" <Alistair@NoSpam.Sodoff> wrote in message
news:4197658a$1@newsgroups.borland.com...

> how do I pass the address of a function, that is within
> my class, to the windows procedure in RegisterClass ?

The window procedure must be a standalone function, not a class method.  If
you must use a class method, then you have to declare the function as
'static'.  But then the static method can't access the class data when it is
called.

> I can pass in a static function, but knowing then
> which instance of the class that called it....

The only way to do that with a static method is if you only have one
instance of the class, in which case you can use a global variable to store
the instance pointer.

> There must be a way of passing the instance objects function
> to the RegisterClass so it calls it when a message is sent.

There is, but it is not as simple as you would like.  You have to write a
proxy function.  The proxy forwards the messages for a particular class type
to a specific class instance.  Then you pass the proxy function to
RegisterClass() for each instance of the class you instantiate.

The trick, however, is that the proxy function has to be created dynamically
at runtime, not written statically at compile time.  This is because a fresh
copy of the proxy code has to be allocated in dynamic memory for each class
instance that is instantiated, and the memory filled with straight assembly
code that is specific to that class instance.  The proxy has to directly
manipulate the stack in order to correctly set up the parameters for the
specific class method, including the hidden 'this' pointer.  Hense why a new
copy of the proxy has to be allocated in memory for each class instance -
each copy of the proxy handles a separate 'this' pointer.

If you don't want to do all of that yourself, and don't mind using the VCL,
then you can use the VCL's MakeObjectInstance() function.  It does all of
that work for you.  It is the same function that the VCL uses for its own
class-method-based window procedures.  You pass it a class method pointer
and it returns a suitable pointer for use with RegisterClass().  When you
are done with the class instance, you can then pass the pointer back to
FreeObjectInstance() to release the memory.


Gambit
Technical Details
Message-ID: <4198f08f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4197658a$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,896683d16cbc3ca2
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: <4197658a$1@newsgroups.borland.com>
Subject: Re: Function Address Help
Date: Mon, 15 Nov 2004 10:09:57 -0800
Lines: 49
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: <4198f08f$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1100542095 68.69.17.41 (15 Nov 2004 10:08:15 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail