Click here to Skip to main content
15,903,201 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: finding folders Pin
valikac11-Jun-03 10:48
valikac11-Jun-03 10:48 
GeneralRe: finding folders Pin
Steve L.11-Jun-03 11:17
Steve L.11-Jun-03 11:17 
GeneralRe: finding folders Pin
valikac11-Jun-03 11:25
valikac11-Jun-03 11:25 
GeneralRe: finding folders Pin
Anonymous11-Jun-03 21:21
Anonymous11-Jun-03 21:21 
Generalclass troubles! Pin
John Kohn11-Jun-03 10:20
sussJohn Kohn11-Jun-03 10:20 
GeneralRe: class troubles! Pin
Joaquín M López Muñoz11-Jun-03 10:26
Joaquín M López Muñoz11-Jun-03 10:26 
GeneralRe: class troubles! Pin
John Kohn11-Jun-03 11:19
sussJohn Kohn11-Jun-03 11:19 
GeneralRe: class troubles! Pin
Joaquín M López Muñoz11-Jun-03 11:50
Joaquín M López Muñoz11-Jun-03 11:50 
Well, Mike's FAQ explains it all, but I'll try to clear the issue up myself. Non-static members have, so to say, a hidden parameter pointing to the object the member function applies to (the this parameter, if you want to see it like that). After changing ListningForClients to static, the member function is no longer bound to any particular object via this, hence the error. This is what static means when applies to member functions: general functions not associated to particular instances of the class.
The way out of this problem is to use a callback paramter CreateThread provides just for this sort of things. In this parameter you can store a pointer to the relevant object and then use it accordingly. Pseudocode follows:
class CNetwork
{
  ...
  static DWORD WINAPI StaticListeningForClients(LPVOID Arg1)
  {
   CNetwork* object=(CNetwork*)(Arg1); // the object passed in CreateThread
   object->ListeningForClients();
  }
 
  void ListeningForClients() //non-static
  {
    // the real stuff here
  }

  ...
  CreateThread( NULL, 0, &ListeningForClients, this, 0, 0);
  // Here's the trick, we're passing this as the callback parameter
};
Hope you get the idea. Please read the FAQ for further clarification. Good luck.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralRe: class troubles! Pin
basementman12-Jun-03 6:37
basementman12-Jun-03 6:37 
GeneralHelp with .EXE file Pin
alexboza11-Jun-03 10:04
alexboza11-Jun-03 10:04 
GeneralRe: Help with .EXE file Pin
David Crow11-Jun-03 10:28
David Crow11-Jun-03 10:28 
GeneralRe: Help with .EXE file Pin
kochhar11-Jun-03 12:40
kochhar11-Jun-03 12:40 
QuestionGDI+ what happened to GetPixel() ? Pin
Greg Ellis11-Jun-03 9:53
Greg Ellis11-Jun-03 9:53 
GeneralByte-swapping... Pin
Nitron11-Jun-03 9:50
Nitron11-Jun-03 9:50 
GeneralRe: Byte-swapping... Pin
Joaquín M López Muñoz11-Jun-03 10:07
Joaquín M López Muñoz11-Jun-03 10:07 
GeneralRe: Byte-swapping... Pin
Nitron11-Jun-03 10:12
Nitron11-Jun-03 10:12 
GeneralRe: Byte-swapping... Pin
Joaquín M López Muñoz11-Jun-03 10:23
Joaquín M López Muñoz11-Jun-03 10:23 
GeneralRe: Byte-swapping... Pin
John M. Drescher11-Jun-03 10:07
John M. Drescher11-Jun-03 10:07 
GeneralRe: Byte-swapping... Pin
PJ Arends11-Jun-03 15:52
professionalPJ Arends11-Jun-03 15:52 
GeneralRe: Byte-swapping... Pin
Nitron12-Jun-03 3:44
Nitron12-Jun-03 3:44 
GeneralRe: Byte-swapping... Pin
Johnny ²12-Jun-03 4:24
Johnny ²12-Jun-03 4:24 
GeneralRe: Byte-swapping... Pin
Nitron12-Jun-03 4:27
Nitron12-Jun-03 4:27 
GeneralRe: Byte-swapping... Pin
Peter Weyzen12-Jun-03 20:58
Peter Weyzen12-Jun-03 20:58 
Generalstrange problem occur while trying to access member function through static function Pin
yccheok11-Jun-03 9:32
yccheok11-Jun-03 9:32 
GeneralRe: strange problem occur while trying to access member function through static function Pin
Phil Hamer11-Jun-03 11:56
Phil Hamer11-Jun-03 11:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.