home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / mswindo / programm / misc / 3244 < prev    next >
Encoding:
Internet Message Format  |  1992-11-05  |  1.9 KB

  1. Path: sparky!uunet!lax.pe-nelson.com!lax!twbrown
  2. From: twbrown@PE-Nelson.COM (Tom W. Brown)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: Typecasting a pointer to member-function to unsigned long
  5. Message-ID: <685@lax.lax.pe-nelson.com>
  6. Date: 5 Nov 92 18:13:39 GMT
  7. References: <runehh.97.720902695@dhhalden.no>
  8. Sender: news@lax.pe-nelson.com
  9. Organization: PE-Nelson
  10. Lines: 32
  11.  
  12. In article <runehh.97.720902695@dhhalden.no>, runehh@dhhalden.no (RUNE HALFDAN HOLST HUSEBY) writes:
  13. |> 
  14. |> In a project I'm working on, I need to typecast a (far) pointer to a 
  15. |> function to an unsigned long (DWORD). I need to do this because the 
  16. |> MS Windows API requires me to do such a thing.
  17. |> 
  18. |> This is the line that causes the error:
  19. |> 
  20. |>         SetWindowLong(GetDlgItem(HWindow, ID_TO), GWL_WNDPROC, 
  21. |>                                 (DWORD)&WCompose::ComboProc);
  22. |> 
  23. |> What I'm trying to do, is to send over a callback function, using a generic 
  24. |> function which set a lot of different properties, all the size of a long.
  25. |> Thus I need to typecast the function pointer to an unsigned long.
  26.  
  27. Danger, Will Robinson, danger, danger !!! :-)
  28.  
  29. A pointer to member function cannot be given to Windows as a callback because
  30. Windows does not know how to supply the 'this' parameter.  However, if the
  31. function is declared as 'static' you may do so (since static member functions
  32. don't get a 'this' pointer).
  33.  
  34. So, assuming that WCompose::ComboProc is declared as a static member
  35. function, the above syntax should work.  I gather it does not, so you may
  36. want to double check that this function is, indeed, static.
  37.  
  38.  
  39. ----------------------------------------------------------------------------
  40. Tom Brown               |  "'ow d'you know 'e's a king?
  41. PE Nelson Systems       |            'cause 'e 'asn't got shit all over 'im!"
  42. twbrown@pe-nelson.com   |                    Monty Python and the Holy Grail
  43. ----------------------------------------------------------------------------
  44.