|
The problem is that you pass to AfxBeginThread a member function of a class. This won't work because a member function does't not have the same calling convention as a standard function (the this pointer is passed implicitely).
Thus you need to use a global function. If your thread needs to access some member variables of the class that started the thread, you can pass the pointer to the class in the parameter:
UINT getTime(LPVOID param)<br />
{<br />
CMyThreadDlg* pDlg = (CMyThreadDlg*)param;<br />
<br />
<br />
return 0;<br />
}<br />
And to spawn the thread:
void CMyThreadrDlg::OnCreateThread() <br />
{<br />
if (m_check)
{<br />
CWinThread *pThread = AfxBeginThread(getTime, this);
}<br />
}<br />
Also, you don't need to call AfxEndThread before leaving the thread function because the thread will automatically finishes when this function exits.
|
|
|
|
|
But if you want absolutely that the thread procedure be a member of the class, there is a simple solution: declare the thread procedure as static function member and pass this pointer as parameter to the thread, so that you are able to call a non-static member function of the class as true thread procedure.
class A<br />
{<br />
public:<br />
VOID StartThread();<br />
<br />
private:<br />
static LRESULT ThreadProc(LPVOID pParam);<br />
VOID DoThread();<br />
}<br />
<br />
VOID A::StartThread()<br />
{<br />
AfxBeginThread(ThreadProc, this);<br />
}<br />
<br />
LRESULT A::ThreadProc (LPVOID pParam)<br />
{<br />
A *This = (A*)pParam;<br />
This->DoThread();<br />
return 0L;<br />
}<br />
<br />
VOID A::DoThread()<br />
{<br />
}
|
|
|
|
|
Yes of course...
But the only advantage I see in this method is to avoid having a global function. Is there any other advantage ?
|
|
|
|
|
It's perhaps only a matter of design but I assume that the worker thread is part of the object and is related to its internal working. So for me, it makes sense that the thread procedure be physically a function member of the class so that it can access to other private data (which the global function can't) Anyway I don't like too much global functions in C++.
|
|
|
|
|
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I need to construct a parser.My application is in MFC.
How to build a parser with simple construction procedure.
It also has to applicable for the project objects.
please avoid the concept of Activex scripting...
|
|
|
|
|
Not sure to understand what you mean. If you need to parse a string containing items separated by known constant characters, it may be sufficient to use CString::Tokenize ; then you need to build a structure representing the logical content of the string, so that it will be easier then to manipulate the data. It's actually a very vast subject.
|
|
|
|
|
not sure i understand neither, but if you want a not too difficult method to parsing a language, you could read my article VisualCalc...
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
You getting very fast these days, How dare, you use your HAND for TYPING!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
dittygrail wrote:
I need to construct a parser.My application is in MFC.
What type of Parser do u want to Create, i.e. XML parser, HTML parser etc.....
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
What type of Parser do u want to Create, i.e. XML parser, HTML parser etc.....
no, only a parser !!!
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
only a parser
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
With both you discussing here, this is the most colorful message thread I've ever seen on CP
|
|
|
|
|
|
Oh my! I became a member of the club of the colorful people! So cool!
|
|
|
|
|
Stlan wrote:
Oh my! I became a member of the club of the colorful people! So
But you forget to color your username, Don't worry for this time, I have colored that for you. But this is last time
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
I have colored that for you
How do you color your username?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Bob Stanneveld wrote:
How do you color your username?
use HTML tags like this, if you want to color you username RED
<b> <font color=#ff0000>Bob Stanneveld </font></b>
which make your username something like this :-
Bob Stanneveld
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
I thought that the HTML tags didn't work inside your username. Guess it does. Thanks!
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Bob Stanneveld wrote:
Guess it does.
So whats your new color
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Nothing special yet. My favorite colours are already taken, blue by you and black by everyone else who doesn't bother to change the colour of their name...
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
|
|