By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 940 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

I cannot use the AfxBeginThread, please help. Urgent

P: n/a
Dear members:
I want to use the multithread in my program which is developed in
Visual C++ platform (version 6).

I created a controlling function:
UINT CCOMM1Dlg::WritingThreadFunc(LPVOID pParam) for a thread

The reason that I want it to belong to the class CCOMM1Dlg is that in
this function I need to process some member variables of the class.

The problem is that when I start the thread using:
int temp;
temp=1;
CWinThread* m_pWritingThread;
m_pWritingThread=AfxBeginThread(WritingThreadFunc, &temp);

The compiler shows the error:'AfxBeginThread':none of the 2 overloads
can convert parameter 1 from type 'unsigned int (void *)'

However, when I move the controlling function out of the class like
this:
UINT WritingThreadFunc(LPVOID pParam), no error appears.

Please help me to solve this problem, as I mentioned above, I need to
use the function in the class because it would process a lot of
member-variables of the class.

It is urgent to me, so please do help.

I look forward to your answers./

Thank you

LiuJU
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Liu Ju" <ch*********@hotmail.com> wrote in message
news:8c*************************@posting.google.co m...
Dear members:
I want to use the multithread in my program which is developed in
Visual C++ platform (version 6).

I created a controlling function:
UINT CCOMM1Dlg::WritingThreadFunc(LPVOID pParam) for a thread

The reason that I want it to belong to the class CCOMM1Dlg is that in
this function I need to process some member variables of the class.

The problem is that when I start the thread using:
int temp;
temp=1;
CWinThread* m_pWritingThread;
m_pWritingThread=AfxBeginThread(WritingThreadFunc, &temp);

The compiler shows the error:'AfxBeginThread':none of the 2 overloads
can convert parameter 1 from type 'unsigned int (void *)'

However, when I move the controlling function out of the class like
this:
UINT WritingThreadFunc(LPVOID pParam), no error appears.

Please help me to solve this problem, as I mentioned above, I need to
use the function in the class because it would process a lot of
member-variables of the class.

It is urgent to me, so please do help.

I look forward to your answers./


You must pass a function outside of any class to AfxBeginThread, but there
is no reason that function cannot call a function inside a class. Like this

UINT WritingThreadFunc(LPVOID pParam);
{
return ((CCOMM1Dlg*)pParam)->WritingThreadFunc();
}

To make this work just have to pass a pointer to a CCOMM1Dlg object as the
second parameter to AfxBeginThread (currently you as passing a pointer to
temp for some reason). This pointer will then get passed as pParam to you
function. Like this

CCOMM1Dlg someDlg;
m_pWritingThread=AfxBeginThread(WritingThreadFunc, &someDlg);

or if you are inside the object already like this
m_pWritingThread=AfxBeginThread(WritingThreadFunc, this);

John
Jul 22 '05 #2

P: n/a
Hi John Harrison:
Now it works very smootly. Thank you very much. I am not good at
Visual C++, can I correspond with you through your personal email
address if I face problems in programming?
I look forward to your reply.

Thank you.

Sincerely,

LiuJu,
Jul 22 '05 #3

P: n/a

"Liu Ju" <ch*********@hotmail.com> wrote in message
news:8c**************************@posting.google.c om...
Hi John Harrison:
Now it works very smootly. Thank you very much. I am not good at
Visual C++, can I correspond with you through your personal email
address if I face problems in programming?
I look forward to your reply.


No problem, glad to help. But I'd rather you didn't email me personally, but
you can post to this group. Many people on this group can help you, not just
me.

Also please remember that Visual C++ problems are off topic on this group.
C++ language questions only here. For Visual C++ you can try
news:comp.os.ms-windows.programmer.win32 for instance.

john
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.