Multi-threading question regarding MFC in a DLL..

Pardon for the stupid noobish question:

WinXP Pro, VS .Net 2003

I have a client application which uses MFC (MFC dynamically linked)
I have a DLL which uses MFC (regular DLL, MFC dynamically linked)

The app calls ::LoadLibrary to load in the DLL, the DLL (when it
initializes) creates a thread for performing calculations.
The app then uses ::GetProcAddress to explicitly link to the exported DLL
functions.

Each exported DLL function's first line of code is:

    AFX_MANAGE_STATE( AfxGetStaticModuleState() );

As a test, I do something I know is bad, I have a string that is accessed
(for reading by the DLL's calc thread, for writing by the calling app's
thread) by both the app thread and the calculation thread.  It is a CString.

I wanted to know whether the module state that I am 'maintaining' applies to
client (of the DLL) threads only  and that the calculation thread can access
the changing value of my CString (remember, this is just as a test)?

Or, can the calc thread get the CString value because it happens to be a
very simple MFC class and this would not work (regardless of proper
sychnronization) if it were (for instance) a CMap?

Basically, I want to know if I'm going to screw up MFC by trying to offer
(proper) read/write access to two different threads (between the app thread
which instantiated the DLL, and the calculation thread)?  I don't know much
about MFC's management of state and what is or isn't thread locale
storage...

    WTH


0
ih8spam (77)
1/28/2004 6:41:44 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
444 Views

Similar Articles

[PageSpeed] 41

WTH wrote:

> Pardon for the stupid noobish question:
> 
> WinXP Pro, VS .Net 2003
> 
> I have a client application which uses MFC (MFC dynamically linked)
> I have a DLL which uses MFC (regular DLL, MFC dynamically linked)
> 
> The app calls ::LoadLibrary to load in the DLL, the DLL (when it
> initializes) creates a thread for performing calculations.
> The app then uses ::GetProcAddress to explicitly link to the exported DLL
> functions.
> 
> Each exported DLL function's first line of code is:
> 
>     AFX_MANAGE_STATE( AfxGetStaticModuleState() );
> 
> As a test, I do something I know is bad, I have a string that is accessed
> (for reading by the DLL's calc thread, for writing by the calling app's
> thread) by both the app thread and the calculation thread.  It is a CString.
> 
> I wanted to know whether the module state that I am 'maintaining' applies to
> client (of the DLL) threads only  and that the calculation thread can access
> the changing value of my CString (remember, this is just as a test)?
> 
> Or, can the calc thread get the CString value because it happens to be a
> very simple MFC class and this would not work (regardless of proper
> sychnronization) if it were (for instance) a CMap?
> 
> Basically, I want to know if I'm going to screw up MFC by trying to offer
> (proper) read/write access to two different threads (between the app thread
> which instantiated the DLL, and the calculation thread)?  I don't know much
> about MFC's management of state and what is or isn't thread locale
> storage...
> 
>     WTH
> 
> 

AFAIK the state management is unrelated to threads.  Two threads can 
access an MFC object, except for CWnd, if they use synchronization.  The 
CWnd-to-HWND map is "hidden" in thread local storage so two threads 
can't access the same window.

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
1/29/2004 1:25:02 AM
> AFAIK the state management is unrelated to threads.  Two threads can
> access an MFC object, except for CWnd, if they use synchronization.  The
> CWnd-to-HWND map is "hidden" in thread local storage so two threads
> can't access the same window.

I was asking mostly because I know that CWnd can't and that
CSocket/CAsyncSocket can't; ergo, I wondered if this was the default cause
for MFC classes.

I assume not from your reply.

    Thanks,

            WTH


0
spamsucks (94)
1/29/2004 6:22:11 AM
Oops, "case"...

    WTH

"WTH" <spamsucks@Ih8it.com> wrote in message
news:OxWR8Aj5DHA.2312@TK2MSFTNGP12.phx.gbl...
> > AFAIK the state management is unrelated to threads.  Two threads can
> > access an MFC object, except for CWnd, if they use synchronization.  The
> > CWnd-to-HWND map is "hidden" in thread local storage so two threads
> > can't access the same window.
>
> I was asking mostly because I know that CWnd can't and that
> CSocket/CAsyncSocket can't; ergo, I wondered if this was the default cause
> for MFC classes.
>
> I assume not from your reply.
>
>     Thanks,
>
>             WTH
>
>


0
spamsucks (94)
1/29/2004 6:24:05 AM
Reply:

Similar Artilces:

Evaluating during Trial period
Our group is assessing various Org Charting software. Can someone tell me if the following is possible in Visio and if so provide a quick outline of what would have to be done? We have multiple users that need to create Org Charts using the same format, including a legend. The data will be retrieved via an ODBC connection (we have this part functioning with the trial version). Is there a way, when the data is being loaded, to use a customized Org Chart wizard or template? I see how to apply a custom template when manually creating a new chart, but is there a way to apply it when auto...

Array Question Part 2
Some of this is extremely new to me. Code below is info I have been piecing together. From what I can determine the line below doesn't appear to be saving/appending my object $myCollection += new-object PSObject -properties $myServerObject If I use write-output on any of the select-strings commands it is properly updating $myServerObject with the expected value. Does any one see what is wrong with this code? $Servers = Import-CSV -Path $fileServers # Create an array to store objects $myCollection = @() # Parse all the servers foreach($Server in $Servers) { ...

medctroc.dll could not be loaded
I am trying to start managment services and I get the erro "Setup library medctroc.dll could not be loaded, or function MedCtrOCISetupProc could not be found. Contact your system administrator. The specific error code is 0x7e" What do I do thanks, "Janis" <Janis@discussions.microsoft.com> wrote in message news:D96FCDF1-FCC8-4814-AE92-5FD8F5D4865D@microsoft.com... >I am trying to start managment services and I get the erro > "Setup library medctroc.dll could not be loaded, or function > MedCtrOCISetupProc could not be found. > Contact yo...

pivot table question #2
I have two columns of data: Date Value 1/1/05 9 1/1/05 10 1/1/05 12 .... .... 1/9/05 16 1/9/05 4 There may be a variable number of dates, and does not contain a complete list of consecutive dates (i.e. some dates have no associated data and are not in the list) I want to produce a calculation the that subtracts the MIN for each date from the MAX of each date. I do not necessarily have to display the max and min values - I am really after the result Date (max - min) 1/1/05 3 <12-9=3> 1/9/05 12 <16-4> What is the best way to do this? I have experimen...

a question about dlls compatibility between vc7 and vc6
I will develop a program with vc7,but that program should base another dll which is developed by vc6,and I have no that dll's code.and then it's not compatible anymore.How can I do it?thanx ********************************************************************** Sent via Fuzzy Software @ http://www.fuzzysoftware.com/ Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources... That all depends upon what these dlls depend upon. If they depend upon MFC, you will have issues as now you link/load two versions of MFC. If your modules depend upon common system...

Outlook 2000 Mail Question
Hello, I remember years ago, you could "unsend" a sent message. I can't seem to find that option anymore. Does anyone know if this is possible? Thanks for your help. Jean If you are using Exchange, the mail was sent within the same exchange organization, the user has not opened the mail, you have sacrificed a virgin 16 years, 3 months, and 23 days old, included an egg-laying rooster, and performed the sacred (and secret) dance au naturel around a manzanita bonfire build by a Yangnee Indian, you MIGHT be able to recall it by going to the sent items folder, selecting Actions...

Folder Question
Hi, I have a folder that contains about 300 emails. I'd like to export only the addresses of those 300 emails to a flat text file. Is there any simple way to do this? Thanks. ...

PreTranslateMessage in the DLL is not called
Hi there. I have a strange thing in my code. I have a class which is derived from CEdit. In that class there is a PreTranslateMessage method. It is called when I compile this class in the Exe. But it is not never called when I compile this class as a DLL and load it dynamically by LoadLibrary and use the class. Please do you have any ideas what is wrong there? What is the difference of using derived class as a exe or as a dll? Thanks! German Koninin Is it a Regular DLL? Is the CEdit derived object in a modeless dialog? --- Ajay German Koninin wrote: > Hi there. > I have a stra...

question about superscripting
I am using the following formula to generate a replica of the trendline information for a scatter plot: ="y = " & TEXT(intercept,"##0.0##x") & IF(slope>0," +"," ") & TEXT(slope,"##0.0##") & CHAR(10) & "R2 = " & TEXT(rsquared,"##0.0##"), where intercept, slope & rsquared are calculated separately. Is there a way to superscript the "2" in the R2 part? I cannot format as I usually would (ctr-1 does nothing). Is there a CHAR equivalent of superscripting? If so, what is the CHAR ...

Basic Question #2
....I hope. I just started doing my own VBA Programming and I'm stuck. I've created a formula that is just a series of nested ifs (12). I'd like to be able to dragged the cell containing the formula and have the REF change as I drag it, but right now the formula is not variable and REF's only one set of cells when I try to drag it. here's my formula... Function CalcDate(pVal As String) As Long If pVal = "1" Then CalcDate = Range("I4").Value ElseIf pVal = "2" Then CalcDate = Range("I12").Value Else...

Date Question 05-31-07
I have created a database to store photographs and one of the entries is the date the photo was taken. Unfortunately, many times the date is not complete. In some cases the day is missing, in some cases the day and month are missing and in rare cases, the entire date is missing. I have initially set up the date as three text fields to accommodate the possibility of the missing values. Are there any other solutions to the problem? I'd like to use a single date field if possible. George L. Unless you will always have complete dates, or unless you want to use a "default" da...

wxWindget and MFC
I don't know if this is a proper group to post this message... So, if someone think this is crossposting, please forgive me! Recently a friend introduce me a nice library called wxWidget (http://www.wxwidget.com). To me, it seems a lot like MFC but it supports cross platform development... Browsing the web I found a tool to build "forms", visually, for wxWidget library... My question is: Does anyone here knows about a tool to build "forms" (not dialog based) for MFC? []s Fred > My question is: Does anyone here knows about a tool to build "forms"...

Dcount question
I know how to do the Dcount below. My question is how to do two queries with it? I need to pull in a student ID and a range of Scores. I tried many combinations and can't get it right. the other Field is named Scores in tblScoresReport I would like to have all that is less than 70 percent. =Dcount("*", "tblScoresReport","[StudentID] ='IdNumber") If I understand you correctly, you will probably have a table which contains a list of all the subjects avalable an Exam table linked to the the Subjects table which gives the Exam details (eg date of exam),...

VSS Writer Backup questions
We have been using ntbackup to backup our information stores on several servers and then storing this at a separate location. The problem we've run into is how the ntbackup file causes our VSS Shadow Copies for Shared Folders to use a ton of space (every full backup rewrites the entire bkf file using the equivalent space in shadow copies). We're now looking at using vshadow to capture the Exchange backup using the Microsoft Exchange Writer. Essentially we want to do the following: 1. One day a week, do a full backup using vshadow and store this offsite. vshadow would use t...

New page in multi column report
I have a report that prints in 3 columns. In one of my Group Footers I have a Page Break, but it only seems to force a new column, not a new page. Can anyone tell me how to force a new page? I'm sure I found an example previously somewhere showing how this is done, but I can't find it anymore. Thanks, Richard ...

Question Asked Grays out... Is this Normal
Hi, I posted a Question but in The list its Grayed out... Is that Normal... or Some thing Wrong with my Windows Live... Mail ? thanks.. And Thanks ALL MVPs... Khalak On Fri, 26 Mar 2010 23:02:04 -0700, "Khalakmu" <khalakmu@hotmail.com> wrote: >Hi, > > I posted a Question but in The list its Grayed out... Is that Normal... >or Some thing Wrong with my >Windows Live... Mail ? > >thanks.. > And Thanks ALL MVPs... >Khalak I would suggest asking the question in a forum supporting Windows Live Mail. This forum is...

DateAdd question 06-28-07
Im trying to get all the files with any time posted 3 hours earlier than the current time. I'm using the DateAdd but it does not return files DateAdd("h", -3, Date) So if Date = 06/28/07 04:50pm I want the code to return any files dated on or before 06/28/07 01:50pm but for some reason the DateAdd above does not return any files. even if I have files dated befire 06/28/07 04:50 ref: .PropertyTests.Add Name:="Last Modified", _ Condition:=msoConditionOnOrBefore, _ Value:=DateAdd("h", -3, Date), _ I could make ...

APPCRASH iexplore.exe
Dear Ma'am/Sir, All the time I get the same detailed message (IE8 crashes) mentioned below. I already tried to reset IE8 as suggested but no luck :( Could you please send me a procedure how to get rid of this annoying problem? Thanks in advance! Gebeurtenisnaam van probleem:APPCRASH Naam van de toepassing: iexplore.exe Versie van toepassing: 8.0.6001.18865 Tijdstempel van toepassing: 4b077416 Naam van foutmodule: IEShims.dll Versie van foutmodule: 8.0.6001.18865 Tijdstempel van foutmodule: 4b078a27 Uitzonderingscode: c0000005 Uitzonderin...

List Control Box in MFC
I am working on making a control box with MFC and I have a CStringArray in which I have all the file names stored.. Can anyone help me with where i can find code for making the controlbox. thanks in advance UMR_Smoker Do you mean a ListBox? What code? Why not use the resource editor to insert a ListBox. You can populate it using CListBox::AddString in OnInitDialog(if its a dialog app). ----------- Ajay Kalra ajaykalra@yahoo.com UMR_Smoker wrote: > I am working on making a control box with MFC and I have a CStringArray > in which I have all the file names stored.. Can anyone help ...

Checkbook Balance question
What is the difference between "Current Checkbook Balance" and "Current Cash Account Balance"? I always end up with two different amounts. Thank you in advance. Jeremy, Current Checkbook Balance is what the checkbook account balance is in the Bank Rec module. Current Cash Account Balance is what's in the GL account corresponding to the Checkbook. There are a number of things that could cause them to be different: - not everything is posted in the GL - not everything is 'deposited' in Bank Rec - something was entered directly in GL against the cash accou...

File not found: VBA6.DLL
Hi there, currently i'm using GP 2010, Windows Server 2008 (32-bit) and Office 2010. The problem is, when i try to print on screen i got this error messages "File not found: VBA6.dll"? Can anyone help me on this? Thank you. ...

Simple CComboBox question
I have a combobox with some info the user can choose. But how can i make sure the user is only able to chose my predefined information, and is not able to edit the chosen value in the combobox. My problem now is that the user can erase the selected value, i want to make sure he can't edit the edit field of the combobox. grtz Make the style "drop list" and the control is no longer editable. joe On 3 Sep 2004 08:20:05 -0700, voorspoels@hotmail.com (Tim) wrote: >I have a combobox with some info the user can choose. >But how can i make sure the user is only able to chos...

Please advise why I get an Error Message "Prop Res DLL"
When I try to open certain Word documents I get an error message that says "PROP RES DLL". After clicking the OK button several times I get another error message stating "the printer has not responded...........Do you want to continue to wait" and with a Yes No box. If I click the No button the Word document will open. I have re-installed my printer driver (Lexmark) and added any updates from their web site. I am using Windows XP and Office 2003. This is an Excel forum. Not Word, but I'll answer your question. The problem occurs with installing and uninstalli...

dialog box running in a thread? why???
hi, i've just started working on this application, and i found that dialog box is made to run in another thread. actual scenario is like this : void CMyView::OnLButtonDown() { CMyDlg dlg; dlg.DoModal(); //overridden; see implementation in next function } CMyDlg::DoModal() { < create thread here thru AfxBeginThread, passing this pointer in LPARAM > // see // thread implementation in next function HANDLE h[1]; h[0] = pThread->m_hThread; while( true ) { MSG msg; while( PeekMessage( &...

Word 2003 question
Is there anyway to change the default in word when opening a document that has mark ups from view final with markups to just view final? My customer doesn't want to have to change this option everytime she opens a document with changes. So far I haven't been able to find any documentation that suggests I can change this default. Any help would be appreciated. Thank you. jen I would suggest asking in the public.word.newusers newsgroup rather than in this (Outlook) newsgroup. BTW, what your user wants is risky if the document is ever sent electronically. People seldom want the fi...