473,399 Members | 3,832 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,399 software developers and data experts.

Help, cannot populate a list box when calling a thread function using AfxBeginThread

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 seemed to better suit my question.

I am trying to initiate a thread to populate a list box when I click on a button. Once I figure out I will be populating the list box with more complex code, but if I can't even get this to work, I can't move forward on the next part. I am trying to make the following code work but it is obviously not correct:

void CDialogDlg::OnButton1()
{
AfxBeginThread(CDialogDlg::MyThreadFunction,(LPVOI D)this);
}

UINT CDialogDlg::MyThreadFunction(LPVOID lparam)
{
m_listbox.AddString("testfromfunction");
return 0;
}

This code produces the following error:
'AfxBeginThread':none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'

If I change it to the following code, AfxBeginThread works just fine, but I cannot populate the listbox because the MyThreadFunction does not know anything about the m_listbox variable, let alone the AddString member function:

void CDialogDlg::OnButton1()
{
AfxBeginThread(MyThreadFunction,(LPVOID)this);
}

UINT MyThreadFunction(LPVOID lparam)
{
AfxMessageBox("testfromfunction");
return 0;
}

Any help would be greatly appreciated,

Thanks
May 19 '07 #1
2 2327
I got it to work! I had to pass a pointer to the m_listbox variable I created in the AfxBeginThread function and then call it from a static function. Here is how I did it:

UINT MyThreadFunction(LPVOID lparam)
{
((CListBox*)lparam)->AddString("testfromfunction");
return 0;
}

void CDialogDlg::OnButton1()
{
AfxBeginThread(MyThreadFunction,&m_listbox);
}



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 seemed to better suit my question.

I am trying to initiate a thread to populate a list box when I click on a button. Once I figure out I will be populating the list box with more complex code, but if I can't even get this to work, I can't move forward on the next part. I am trying to make the following code work but it is obviously not correct:

void CDialogDlg::OnButton1()
{
AfxBeginThread(CDialogDlg::MyThreadFunction,(LPVOI D)this);
}

UINT CDialogDlg::MyThreadFunction(LPVOID lparam)
{
m_listbox.AddString("testfromfunction");
return 0;
}

This code produces the following error:
'AfxBeginThread':none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'

If I change it to the following code, AfxBeginThread works just fine, but I cannot populate the listbox because the MyThreadFunction does not know anything about the m_listbox variable, let alone the AddString member function:

void CDialogDlg::OnButton1()
{
AfxBeginThread(MyThreadFunction,(LPVOID)this);
}

UINT MyThreadFunction(LPVOID lparam)
{
AfxMessageBox("testfromfunction");
return 0;
}

Any help would be greatly appreciated,

Thanks
May 19 '07 #2
AdrianH
1,251 Expert 1GB
Great to here. Keep on coding! :)


Adrian
May 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
3
by: Liu Ju | last post by:
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...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: Joachim | last post by:
I'm using MS Visual C++ .NET, Windows XP, and 1GB RAM. Why could be the reason why I get an error message saying Out of memory when running the following code CClientThread* pThread =...
2
by: CW | last post by:
In an earlier thread, I was asking for help on "Invalid attempt to FieldCount when reader is closed" error when I was using a dataset rather than a datareader to bind to a datagrid. After...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
2
by: SStory | last post by:
Here is the situation. I want to display Icons, Type of file etc from a file extension. Upon initial program load I may only need icons for certain files. But other operations will require...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.