www.digitalmars.com         C & C++   DMDScript  

D - How to get address of member-function?

reply Thorn <Thorn_member pathlink.com> writes:
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!
Aug 15 2005
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
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.
Aug 16 2005