Thread overview
How to get address of member-function?
Aug 15, 2005
Thorn
Aug 16, 2005
Stewart Gordon
Sep 15, 2005
too advanced :)
August 15, 2005
Hello everybody! Help me, please.
I try to create Window class (under Win32). As we know we need register window
class with message processing function. We need only simple 32-bit address
(pointer) of that function. I tried to get one in constructor:

this() {
wc.WinProc = &this.MyWinProc;
..

BUT compiler complains that it can't convert from delegate(!!!) to pointer. How
I can obtain it?
Documentation says that even delegate has two parts: object AND address! I want
to take last one :) Thank you!


August 16, 2005
Thorn wrote:
> Hello everybody! Help me, please.

"Everybody" now uses digitalmars.D and its descendant 'groups.  This one is deprecated.  Followup set.

> I try to create Window class (under Win32). As we know we need register window
> class with message processing function. We need only simple 32-bit address
> (pointer) of that function. I tried to get one in constructor:
> 
> this() {
> wc.WinProc = &this.MyWinProc;
> ..
> 
> BUT compiler complains that it can't convert from delegate(!!!) to pointer. How
> I can obtain it?

You can't.  A member function doesn't have an address individual to the object it's called on.

> Documentation says that even delegate has two parts: object AND address! I want
> to take last one :) Thank you!

Exactly.  It's physically impossible to call the function given only one of these bits of information.

Internally, something like this:

    class Qwert {
        int yuiop(uint asdfg) { ... }
    }

looks something like this

    int Qwert.yuiop(Qwert this, uint asdfg) { ... }

not, as you seem to think, as a separate copy of the function for each object.

If there is only one Window object, then make the member static. Otherwise, write a static wrapper function that looks up the HWND.  As SDWF, and probably other GUI libraries, do internally.

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on on the 'group where everyone may benefit.
September 15, 2005
OK, Stewart, thanks for answer. But...

>Internally, something like this:
>
>     class Qwert {
>         int yuiop(uint asdfg) { ... }
>     }
>
>looks something like this
>
>     int Qwert.yuiop(Qwert this, uint asdfg) { ... }
>
>not, as you seem to think, as a separate copy of the function for each object.

Hmm... OK, as I see OOP promises big future but still sit on lumber technologies. :) Theoretically it's possible, but not in this century.