Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
How to execute a dialogue class function from a thread?
 
For example
		static DWORD WINAPI setBitThread(LPVOID lpParam) 
{	
	CUMKurunegalaDlg::OnCbnEditchangePtype(); /*This line give me an error that tell "Non-static member reference must be relative to a specific object */
    return 0; 
} 
Posted 17-Aug-12 19:08pm
Comments
pasztorpisti at 18-Aug-12 4:42am
   
Threading is an advanced topic (especially when mixed with gui). For this reason I wouldn't jump on it before having a solid understanding of the language constructs...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I answered a question like this not too long ago on a message board. Someone else wanted to pop up a messagebox from a thread. Here is my answer to that:
http://www.codeproject.com/Messages/4333885/Re-Messagebox.aspx[^]
In your case you should execute your dialog class function (generally your gui manipulator code) in the WM_USER+XXX message handler of your window, where the other guy show the messagebox.
 
Here is another short answer to something else, very important if you are using MFC:
http://www.codeproject.com/Messages/4334909/Re-Messagebox.aspx[^]
 
EDIT: Actually you have two problems: you don't know how to trigger that action in your dialog, another is that you are trying to do that from a non-gui thread. The first problem is already described by nv3 in another solution.
  Permalink  
v2
Comments
nv3 at 18-Aug-12 5:32am
   
Likewise! You brought in the other half.
Sergey Alexandrovich Kryukov at 18-Aug-12 18:11pm
   
5ed, with the references post as well. --SA
pasztorpisti at 18-Aug-12 18:24pm
   
Thanks!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Your question is unclear to me. But it seems that you are trying to call a non-static (i.e. normal) member function from a static member function. To call a non-static member function you need an object of this class to apply the function to. For example, when you call
 
    pObj->MyFunction ();
 
then MyFunction is applied to the object that pObj points to. Inside MyFunction the this pointer then points to that very object.
 
The nice thing about a this pointer is that you address other member variables or member functions of a class without using a pointer. For example inside MyFunction to following two statements do the same:
 
    this->m_counter = 0;
    m_counter = 0; // does the same
 
or another example:
 
    this->OtherFunctionOfThatClass();
    OtherFunctionOfThatClass(); // does the same
 
Now, static member functions are different in that they don't need and don't have this pointer. That means you can call them from outside your class although you don't have an object to apply the to.
 
Inside a static member function you cannot call a non-static member function of your class without explicitly telling the object you want to apply the function to, because your non-static member function has not this pointer.
 
If you want to call a non-static member from a static member function you must supply an object as a pointer or a reference:
 
void MyClass::MyStaticMemberFunction()
{
    MyNonStaticMemberFunction(); // this is an error
    ...
    MyClass* pOtherObj = ...
    pOtherObj->MyNonStaticMemberFunction(); // that will work
}
  Permalink  
Comments
pasztorpisti at 18-Aug-12 4:39am
   
5ed, You answered the actual problem of OP, for some reason I saw only the other problem... :-)
Sergey Alexandrovich Kryukov at 18-Aug-12 18:11pm
   
5 from me, too. --SA
nv3 at 18-Aug-12 18:43pm
   
Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 1,300
1 Sergey Alexandrovich Kryukov 660
2 ravikhoda 300
3 OriginalGriff 299
4 Manas Bhardwaj 240
0 Sergey Alexandrovich Kryukov 11,194
1 OriginalGriff 6,867
2 Peter Leow 4,795
3 Abhinav S 3,838
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 18 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid