473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

I cannot use the AfxBeginThread, please help. Urgent

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
3 6684

"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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: raj | last post by:
Hi, I just want to know the difference between thread created by CreateThread and AfxBeginThread function. I got one problem when using the CreateThread. The appliction malfunction while using the...
17
by: Saps | last post by:
Hi all. Can anyone help me here. I have loads of .sql files and i need a way to call these from my asp page so the user can run them from the browser. Meaning i have a page with a list of all...
14
by: c676228 | last post by:
Hi everyone, Our site is down, because of our hosting company applied sql server 2000 sp4 on windows 2000 server. right after it applied the service pack, our sql server database is down and...
1
by: rajalingam | last post by:
Server Error in '/library' Application. -------------------------------------------------------------------------------- Server cannot access application directory 'F:\Library Latest Code\'. The...
8
by: Bern McCarty | last post by:
We have a large mixed dll that I can never seem to get to link incrementally. Below is the console output. For simplicity I've eliminated some stuff that we normally do when we really link this...
2
by: phenrol | last post by:
Hello, I am having issues getting my worker thread to function properly. I am working with visual c++ 6 and I am unsure that this is the correct forum to post in but I could not find another that...
4
by: Peter | last post by:
I have the following code which works fine in IE6 and IE7 and FireFox, but when I run IE6 on Citrix I get "The page cannot be displayed" in the iframe. We don't have IE7 on Citrix so I can't try...
4
by: eschneider | last post by:
I get the following error when trying to browse the .asmx. I get the same thing when trying to add a reference. using .NET 2.0 There is no error message. Any ideas? Thanks,
13
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is streamed from handler in ASP.net" at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.