Click here to Skip to main content
15,892,222 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to search Pin
David Crow20-Jun-05 2:35
David Crow20-Jun-05 2:35 
QuestionCan anyone tell me how to make use of ADO from MFC ? Pin
Eytukan20-Jun-05 0:27
Eytukan20-Jun-05 0:27 
AnswerRe: Can anyone tell me how to make use of ADO from MFC ? Pin
Manfred Staiger20-Jun-05 1:25
Manfred Staiger20-Jun-05 1:25 
AnswerRe: Can anyone tell me how to make use of ADO from MFC ? Pin
ThatsAlok20-Jun-05 19:00
ThatsAlok20-Jun-05 19:00 
QuestionWhy threads are declared as Static when used from Class?...? Pin
Eytukan20-Jun-05 0:24
Eytukan20-Jun-05 0:24 
AnswerRe: Why threads are declared as Static when used from Class?...? Pin
toxcct20-Jun-05 1:08
toxcct20-Jun-05 1:08 
AnswerRe: Why threads are declared as Static when used from Class?...? Pin
David Crow20-Jun-05 2:37
David Crow20-Jun-05 2:37 
AnswerRe: Why threads are declared as Static when used from Class?...? Pin
Toby Opferman23-Jun-05 17:24
Toby Opferman23-Jun-05 17:24 
Functions used to be created as threads are defined as "static" when used with a C++ Class because there is an implied parameter that doesn't show up in code, the THIS pointer.

To avoid this confusion and make it simple "static" class members only operate on static data and not per-instance data and as such the "this" pointer is not passed in. So, it's easy to define the function as static and use it in CreateThread without worries. Of course they usually pass the object instance as the first parameter anyway.

class x 
{
  public:
   static DWORD WINAPI MyThread(PVOID lParam)
   {  
      x *pX = (x *)lParam;
      // Happy Happy Joy Joy
   }
}
...
x pX = new x;
CreateThread(...., x::MyThread, pX);


As you see in the above example the thread can be created and the system will pass in the "this" pointer and we will manually re-use it.

Another way to do this in the C++ is to simply define a class function to be standard call, NOT FAST CALL, and take "void" parameters.

  class x 
  {
      public: 
      DWORD WINAPI MyThread(void);
  };
...
x *pX = new x;
CreateThread(..., x::MyThread, pX);


Why void parameters?

Because the system will now pass in the "this" pointer for you and in C++ the language hides this detail anyway.

Why stdcall and not fastcall?

STDCALL should pass the "this" pointer on the stack while fastcall passes the this pointer in ECX register, which the system has no idea about.




8bc7c0ec02c0e404c0cc0680f7018827ebee
Generalgreat one toby! Pin
Eytukan23-Jun-05 23:33
Eytukan23-Jun-05 23:33 
GeneralDisplaying digital Data Pin
a_david12320-Jun-05 0:16
a_david12320-Jun-05 0:16 
GeneralRe: Displaying digital Data Pin
benjymous20-Jun-05 3:22
benjymous20-Jun-05 3:22 
GeneralRe: Displaying digital Data Pin
a_david12320-Jun-05 18:15
a_david12320-Jun-05 18:15 
GeneralUsing a dll in a Dialog based application Pin
Anonymous19-Jun-05 23:44
Anonymous19-Jun-05 23:44 
GeneralRe: Using a dll in a Dialog based application Pin
LCI20-Jun-05 7:08
LCI20-Jun-05 7:08 
GeneralVC++6 to VC++7.1upgrade crashes Pin
Giles19-Jun-05 23:12
Giles19-Jun-05 23:12 
GeneralHTML view on MDI Main Frame background Pin
Jan S.19-Jun-05 22:34
Jan S.19-Jun-05 22:34 
GeneralRunning in Debug Pin
sweep12319-Jun-05 22:32
sweep12319-Jun-05 22:32 
GeneralRe: Running in Debug Pin
BlackDice20-Jun-05 3:49
BlackDice20-Jun-05 3:49 
GeneralWNetConnectionDialog Pin
Still learning how to code19-Jun-05 22:19
Still learning how to code19-Jun-05 22:19 
GeneralRe: WNetConnectionDialog Pin
David Crow20-Jun-05 2:40
David Crow20-Jun-05 2:40 
GeneralRe: WNetConnectionDialog Pin
Still learning how to code20-Jun-05 7:44
Still learning how to code20-Jun-05 7:44 
GeneralRe: WNetConnectionDialog Pin
David Crow20-Jun-05 7:47
David Crow20-Jun-05 7:47 
GeneralRe: WNetConnectionDialog Pin
Still learning how to code20-Jun-05 20:24
Still learning how to code20-Jun-05 20:24 
GeneralRe: WNetConnectionDialog Pin
David Crow21-Jun-05 2:55
David Crow21-Jun-05 2:55 
GeneralRe: WNetConnectionDialog Pin
Still learning how to code21-Jun-05 6:53
Still learning how to code21-Jun-05 6:53 

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.