www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

D - How to get address of member-function?

↑ ↓ ← 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
↑ ↓ → 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