Diaglog/Threading Data Exchange Question

Greetings,

I have learned a lot from all of you, and I hope to over come my latest road 
block. I have a smal IRC Chat client I am making.

I have a Dialog Box with Control and I use a worker thread for connecting to 
IRC - That Thread will update controls on the Dialog by sending 
PostMessages.

Now my problem is in the ListBox Control that I have extended to do popup 
menu with various commands.
I need to be able to read that controls methods from within the Thread.

so I need to do this from within my IRC Socket thread:
(code not exact  - pseudo code)

CListBoxEx myUsers;  //Defined in my DialogClass

(inside my worker thread)
...
CString fromName;
CString inputLine;
.....
if(!myUsers.isIgnored(fromName))
{
    printf(inputLine);
}


So I have learned to do PostMessages from Worker thread to add/remove 
users/add chat text to Dialog...But how can I access
my Dialogs Member Functions like above?






0
kozmo1 (2)
6/20/2008 9:30:17 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
772 Views

Similar Articles

[PageSpeed] 47

Sorry to  update this so Soon.  Is it Thread safe to use something like 
this:

if(!((CTest1Dlg*)m_pMainWnd)->m_users.isIgnore(fromUser)

{



}



0
kozmo1 (2)
6/20/2008 9:38:56 PM
On Fri, 20 Jun 2008 14:38:56 -0700, "Scott Kraemer" <kozmo@koz.com> wrote:

>Sorry to  update this so Soon.  Is it Thread safe to use something like 
>this:
>
>if(!((CTest1Dlg*)m_pMainWnd)->m_users.isIgnore(fromUser)
>
>{
>
>
>
>}
>
>

It depends completely on what isIgnore does.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
6/20/2008 9:56:19 PM
Scott Kraemer wrote:
> Sorry to  update this so Soon.  Is it Thread safe to use something like 
> this:
> 
> if(!((CTest1Dlg*)m_pMainWnd)->m_users.isIgnore(fromUser)
> 
> {
> 
> 
> 
> }

Scott:

What does isIgnore() do? If it just reads a bool that has been set by the main 
thread,I would say this is probably harmless, but if it uses methods of the 
ListBox, I would say don't do this.

But personally, I would use the dreaded SendMessage() for this.

BTW, what is m_pMainWnd in this context? In these dialog-type worker thread 
situations I always make the thread function a static member of the dialog, and 
then cast the LPVOID parameter and delegate to a non-static member. Then you can 
jsut use the class members (though you need to be careful what you do with them).

-- 
David Wilkinson
Visual C++ MVP
0
no-reply8010 (1791)
6/20/2008 10:03:37 PM
I wouldn't try to access anything in any of the UI components in the UI 
thread from a worker thread.  There are just too many chances for problems. 
How about a message handler that you can call with SendMessage() that 
returns true or false.  Then you'd just need the pointer to the dialog 
window and your could send a message to it (SendMessage will wait until the 
message is handled) and you could return your information without going 
through all that indirection.  If you move the window in the future or 
rename it you won't have to change any casts.  All SendMessage needs is a 
CWnd * (or you could use the SDK version with a window handle).

You could pass in a pointer to a CStringArray to have the dialog fill it in 
with the current contents from the list box if you need to see the data ...

Tom

"Scott Kraemer" <kozmo@koz.com> wrote in message 
news:KjV6k.1318$q03.1179@newsfe06.phx...
> Greetings,
>
> I have learned a lot from all of you, and I hope to over come my latest 
> road block. I have a smal IRC Chat client I am making.
>
> I have a Dialog Box with Control and I use a worker thread for connecting 
> to IRC - That Thread will update controls on the Dialog by sending 
> PostMessages.
>
> Now my problem is in the ListBox Control that I have extended to do popup 
> menu with various commands.
> I need to be able to read that controls methods from within the Thread.
>
> so I need to do this from within my IRC Socket thread:
> (code not exact  - pseudo code)
>
> CListBoxEx myUsers;  //Defined in my DialogClass
>
> (inside my worker thread)
> ..
> CString fromName;
> CString inputLine;
> ....
> if(!myUsers.isIgnored(fromName))
> {
>    printf(inputLine);
> }
>
>
> So I have learned to do PostMessages from Worker thread to add/remove 
> users/add chat text to Dialog...But how can I access
> my Dialogs Member Functions like above?
>
>
>
>
>
> 

0
tom.nospam (3240)
6/20/2008 11:02:53 PM
See below...
On Fri, 20 Jun 2008 14:30:17 -0700, "Scott Kraemer" <kozmo@koz.com> wrote:

>Greetings,
>
>I have learned a lot from all of you, and I hope to over come my latest road 
>block. I have a smal IRC Chat client I am making.
>
>I have a Dialog Box with Control and I use a worker thread for connecting to 
>IRC - That Thread will update controls on the Dialog by sending 
>PostMessages.
>
>Now my problem is in the ListBox Control that I have extended to do popup 
>menu with various commands.
>I need to be able to read that controls methods from within the Thread.
****
Absolutely not.  This is already a seriously flawed design decision, and you must NOT read
the controls from within the thread.  To think you should do so is already a fundamental
design error.
****
>
>so I need to do this from within my IRC Socket thread:
>(code not exact  - pseudo code)
>
>CListBoxEx myUsers;  //Defined in my DialogClass
>
>(inside my worker thread)
>..
>CString fromName;
>CString inputLine;
>....
>if(!myUsers.isIgnored(fromName))
>{
>    printf(inputLine);
>}
****
None of this makes sense.  You can't read the contents of the window from another thread,
not reliably in the long term (although you might have the illusion your code is running),
and you CERTAINLY cannot do a "printf" because there is no console.

You will need to inform the thread if there are changes in the control and give it a list
of new values, and use that list.  I would be inclined to do a PostThreadMessage to the
thread that is handling the communication (assuming it has a message pump) and that
message would contain the list of values.  There would be no data sharing between the
threads other than this message.
****
>
>
>So I have learned to do PostMessages from Worker thread to add/remove 
>users/add chat text to Dialog...But how can I access
>my Dialogs Member Functions like above?
****
You can't.  It would be an error to try.  
				joe
****
>
>
>
>
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
6/23/2008 1:23:45 AM
Reply:

Similar Artilces:

Exchange 2003 restore mailbox after AD account deleted
I'm trying to do a restore on an Exchange 2003 cluster from tape. The catch is that the user account has long been deleted and per http://support.microsoft.com/kb/824126/en-us exmerge won't display the mailbox in the recovery group if the original mailbox is moved (or in this case, nonexistent). In our old 2000 restore environment this was easy since we restored to a completely different domain/exchange org and attached the mailbox to a temporary account. In another article we found mention of creating a new AD account and changing the msExchMailboxGUID attribute to match the ...

why CStatic.m_hWnd not valid use realtime thread
Hi All I build an MFC app, and loadlibrary a dll which use high priority (realtime level ) threads for serial communication but after freelibrary the dll, some CStatic and CEdit objects not valid, their m_hWnd becomes to NULL How can I restore these CWnd objects? Is OS release them thanks, waiting online ...

OWA with SSL question
Hello, I have build OWA server to Exchange 5.5 SP4, when I have login to the outlook I have not see there the lock and not get to https I have got the authentication negotiation for user and password but it goes thru port 80 not 443. How I can change it to work with SSL? Thanks in advanced. You have to set the requirements for SSL on the IIS virtual dir, and/or pages.. and have the appropriate keys intalled for IIS. It does not automagically redirect connections to the default http://server/exchange virutal to httpS://server/exchange that is up to you to enforce. "news.mic...

fitting a polynomial to data
Hi, I have three (equal sized) sets of data, T, x and y, and I am trying find the f(T)=x and f(T)=y polynomial approximations, but I can't seem to find the option in Excel that will let me do this. I've been assured by some people that Excel has this option hidden away in it somewhere, but if it's somewhere then the help function is not finding it when seaching on "polynomial fit" or even just "polynomial"... Does anyone know how to do this? Kind regards, - Mike Kamermans Hi Mike, I use polynomials to achieve a curve fit on an x,y scatter chart with t...

Word data recover?
Ok, so I got a phone call from grandma. So the details on what actually happened may be a bit fuzzy. But basically she is writing a very long document, and she has been saving it at about every paragraph, however she hasn't been making back up copies of the file! Anyhow, now when she opens the document, its blank. It seems that maybe she accidentally deleted all the text and then saved it. does anyone know if I can backtrack 3-5 days to get the file back? please let me know! Edit/Delete Message On Wed, 9 Dec 2009 07:35:03 -0800, Firemaple <Firemaple@discussions.micr...

About Data Validation
Hi All I have excel worksheet using Data Validation for control input Value. In the raw data sheet, Define some Name e.g. "DBNAME", AREA","TABLE Name" range It is possible select one DBNAME value, just allow select a particluar list of AREA and TABLE NAME ? e.g. DBNAME AREA Table NAME DB1 A1 T1 DB2 A2 T2 DB3 A3 T3 A4 T4 A5 T5 T6 e.g. When select DB1 just allow user selec...

Exchange SP1 2003 Active sync
I installed 2003 sp1 just over 1 year ago now and my documentation was slightly incomplete. MS KB886346 says that if you have multiple smtp domains in a users email address and that when the primary address is not at the default domain smtp domain (as set by the default recipient policy) that you need to set a SMTPProxy reg key. I remember having issues with active sync trying to get it to work and finding a website that told of a different method and I can't find it again (it was a year ago). All I know is that if I want active synch to work for a user I need to add another smtp...

testing exchange for non delivered messages
Our setup is as follows; an internet e-mail is sent from an outside soucre, it then goes though our SMTP gateway, then on to our Exchange 2003 server. Now I can track the missing random e-mails as such, check the log on the SMTP gateway and see the message has been delivered to Exchange, now once Exchange has the e-mail is there away to track what happens. In some cases e-mails are not making it into the receptants inbox without a way to track I'm at a lost for trouble shooting. Mike you only need to enable message tracking on the Exchange server... -- Susan Conkey [MVP] &qu...

Moving Money data files
I have MS Money 2000 on a desktop and need to move the data from that program to my laptop which has MS Money 2004 Deluxe. I got the .mny file from the MS Money 2000 and burned it on CD to go in MS Money 2004 Deluxe. That worked fine now having a new file created by the new program. But I still don't have the data for checks, deposits,etc in the new 2004 program. Tried my backup floppys to restore the data from the old program to the new one but not having any luck extracting the data I need. Any help? Thanks in advance What your wrote doesn't make sense. You say moving the ....

Pivot Table Chart Question
Hi I run Win2K with Excel 2K I have a pivot table that I run a chart from. The chart works fine, however it does not display the "grand total" from the pivot table. Is there a way that the grand total from the pivot table can be displayed on the chart? Thanks John Pivot charts aren't very flexible, and lack many of the standard options of regular charts. A pivot chart only shows data from the pivot table (you can't add other data), and it shows all data from the pivot table (you can't exclude any), except as you've discovered, totals and subtotals. You coul...

threads #2
I have a server/client application that communicates using threads. The server class uses a while loop inside a thread to wait for new connections in accept state, like this: var a = new var( ); while( (server.Accept(connection)) ) { ...... ...... } I have declared a variable (var) right before this loop which uses memory. I want to free/delete this variable at the end of the while loop, but the control never reaches there. How can I make sure that this variable gets deleted before the server side exits? Thanks. Jessica Jessica Weiner wrote: > I have a server/client applicatio...

Exchange Event log in using SA fails
Setup: Exchange Server 2000 (SP3) on Win2k Server (SP4) The MS Exchange Event Service fails when it uses the Service Account (SA) to log in. The knock on effect of this is that it (we think) deleted the Enterprise Configuration RUS service We got the Enterprise RUS back by installing another Exchange Server on the network (reinstall on the existing one did nothing). I expected this to allow us to create new mailboxes, but it's still failing with Event ID 5. My guess is that Exchange Event needs to use the SA account in order to stamp new mailboxes from RUS. We currently have it usin...

Basic questions re threads and cleaning up
I'm new to C++ and I have some basic questions. I have written an app that does some network stuff in a worker thread. The thread function requests something from the server, gets it and creates an object from the server response. Does this thread terminate/stop/die as soon as it completes its last line of code? Or do I have to do something to kill it? I am used to coding Java so I am totally unsure of what I have to do to "clean up" my variables/objects and free up memory etc. Should I use "delete" for all objects I instantiate? How do I remove remove primitive...

test db with live data
Can someone please list the steps to create copy of live db as test db in Dynamics 7.5, SQL 2000 There is a knowledgebase article in MSB but the web page is not accessible. My experiments end up with a 'lock' icon next to database in 'update database' in GP Utilities with message 'db in use by another user'. Thanks. Here is the TK: Document ID: 22356 Date Created: 6/21/2001 Date Last Modified: 12/12/2003 Language: English - United States Country: USA Product: Great Plains Versions: 5.5, 5.51, 6.0, 7.0, 7.5 Modules: System Manager The information in this document...

2 Questions #2
Thank you!! -- KellyMcG0 ----------------------------------------------------------------------- KellyMcG03's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1454 View this thread: http://www.excelforum.com/showthread.php?threadid=26648 ...

Need help merging a CSV with SQL data
Hi there, I have a shop with an e-procurement site that allows me to update a price list by downloading a CSV file, making the changes, and then uploading it back into there system. The CSV file has the following headings: @UKID - there unique ID for each products Item Name - the name of the item Part NO - our unique ID for each product Price - the price for the product I have an SQL view that shows our unique ID (Part NO) and the price. How can I merge the CSV and the SQL view? Our system does not have the @UKID code, but I don't think it needs it if I can easily merge the 2 toget...

data validation question #4
Within the same Excel Sheet, I am creating an account profile sheet. I have used Data Validation and lists to choose both the account name, and the data fields. When I select the account name, I would like the appropriate data to populate. I would like to have this 'stored' in one sheet versus several. Ex, Account Name: <Microsoft> Field 1: <apples> Field 2: <oranges> or if I choose... Account Name: <XYZ> Field 1: <lemons> Field 2: <grapes> Is there a way to do this? take a look at Debra Dalgleish's site: http://www.contextu...

Linking diaglog windows to buttons
Can anyone please assist with my problem ... I am new to visual C++ and am stuck at what I hope is a relatively straight forward problem... I'm creating a dialog based application in Visual C++ 6.0. I'm finding it impossible to link dialog window buttons to other dialog windows, e.g. I want: if I click button 1 on window 1 and for window 2 to appear, if I click button 2 on window 1 and window 3 appears. I've created the dialog windows, just can't link them. I've managed to get 'yes/no' and 'ok/cancel' message boxes to appear, but nothing more complex tha...

Deleted data
Hi, I have a problem because I deleted some data from my spreadsheet. Please tell me is it possible to get it back ? Details: I was working on my spreadsheet and I deleted some data from it, saved changes and closed Excel. Unless you have back-up copy or are on a server that gets backed up to tape then I am afraid that you have lost the data. -- Sandy In Perth, the ancient capital of Scotland and the crowning place of kings sandymann2@mailinator.com Replace @mailinator.com with @tiscali.co.uk <pitrew@gmail.com> wrote in message news:837e65f9-9196-43b3-b5c3-dd1193f83763@t1g2000p...

auto fill a cell with the same data
i want to fill a cell with '-----'. if it is a wide cell or narrower cell,is there a key stroke that you can precede the character '-' with to fill the entire cell instead of entering the character lots of times to fill it? Thanks - Kev. Format / Cells / Alignment Tab / Horizontal / Fill This will fill the cell with whatever character(s) you put in the cell. -- Regards Ken....................... Microsoft MVP - Excel Sys Spec - Win XP Pro / XL2K & XLXP ---------------------------------------------------------------------------- ...

Importing Data & Refresh Data
I have for some time updating a worksheet in Excel 2002 from a CSV file. The source of that file has now switched from comma separated to tab separated. I can't seem to prevent Excel from trying to read the file wrong. I can't even import the tab-separated file into a blank worksheet within the same Excel file. How do I cancel out Excel's inappropriate knowledge of the file so that I can tell it about the tab-separated version? Thank you, George Is the extension of the file still ".csv"? If so, change it to ".txt" and use the Text Import wizard to import...

Macro to copy and paste all rows of data in between two words
Dear Group This is probably somewhere here on this site but I cannot seem to track it down so I hope someone can help me. I am looking for a macro that can find the word "Start" in column B and then move one row and select all the rows until the word "End" is found in Column B". Then copy from sheet named "Datafrom" to sheet named "Datato". I really hope someone can help with this. Thanks very much in advance. Try; Sub DoIt() Dim rRange As Range On Error Resume Next Set rRange = Range(Range("A:A").Find("...

Exchange 5.5
Hi, I have a multisite exchange 5.5 Installation. I recently got event ID 1091 and error 2147942414 on 2 servers, and fortunately found this KB article Q271744 (http://support.microsoft.com/kb/271744/en-us) I follow up the resolution steps that works well for one server but fails for the other when reaching step 8: I receive error dialog box stating that the mapi call failed. Thi error appear only for inbox and not for outbox, sent item, and deleted items. This confirm that this was not access right error. According to Administrator program, private store, mailbox ressources, the DS ...

Mail Options Questions
This is a multi-part message in MIME format. ------=_NextPart_000_0011_01C7CFA5.E7FF7320 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Can I make it so that : {a) When I do a new mail message and I am in a particular folder, automatically set the 'From' field to a particular email account or (b) If that's not possible, can I tag Contacts such that any messages to them are From a particular email account. (c) Can I automatically categorise received emails depending on the From address ? Thanks ------=_NextPart_000_0011...

Shared hosting and data store
If I want a shared exchange server used by deferent company´┐Żs, how would the best way to have data stores be? Just one data store, or one data store for each company? Are the amount of data stores limited? /C On Exchange Server 2003 Enterprise edition you can have up to 20 stores (max 4 Storage Groups with 5 Stores each). Keeping users from different companies on different stores doesn't really buy you anything unless they're going to have different policies applied to them, or the customer explicitly requests such a setup because of security requirements (such customers will ...