Click here to Skip to main content
16,008,490 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralWarnings compiling STL Pin
30-Mar-01 3:05
suss30-Mar-01 3:05 
GeneralRe: Warnings compiling STL Pin
Chris Losinger30-Mar-01 3:44
professionalChris Losinger30-Mar-01 3:44 
GeneralRe: Warnings compiling STL Pin
Anders Molin31-Mar-01 6:59
professionalAnders Molin31-Mar-01 6:59 
Generalsending messages from a worker thread to cdocument Pin
derhackler29-Mar-01 23:17
derhackler29-Mar-01 23:17 
GeneralRe: sending messages from a worker thread to cdocument Pin
markkuk30-Mar-01 0:09
markkuk30-Mar-01 0:09 
GeneralRe: sending messages from a worker thread to cdocument Pin
derhackler30-Mar-01 0:54
derhackler30-Mar-01 0:54 
GeneralRe: sending messages from a worker thread to cdocument Pin
BenDev30-Mar-01 3:03
BenDev30-Mar-01 3:03 
GeneralRe: sending messages from a worker thread to cdocument Pin
Ajit Jadhav30-Mar-01 6:47
Ajit Jadhav30-Mar-01 6:47 
Hi all:

Let two things sink in. (It took time for me to, anyways!)

(i) He just wants to access just the CDocument-derived object--not a window. CDocument is not derived from CWinThread. There can be command rounting via MFC, but NO message pump.

(ii) This is not a GUI thread, but a worker thread.

So, why bother with window handles and PostMessage API at all?

The solution is as simple as just passing the CMyDocument object as is!

CWinThread* pThread = ::AfxBeginThread( MyWorkerThreadProc, this );


In the worker thread proc
UINT MyWorkerThreadProc( void* pParam )
{
    //
    // ... other worker code
    //
   
    // EVERYTIME using Doc in this thread proc,
    // ensure doc object is still around. (Think MDI app)
    // Some Synch-primitive *necessary* but not shown here.
    if( doc is no longer around )
    {
        // doc ptr is not valid. 
        // Worker thread should terminate immediately.
        return -1;   // returning will destroy this thread automatically
    }
    else
    {
        // Feel free to call any member function of the doc.
        CMyDocument* pDoc = (CMyDocument*) pParam;
        pDoc->CallAnyMemberFunction();
    }
    //
    // ... other worker code
    //

    // Worker task through successfully
    return 1;
}


Pl. correct me if I got something wrong. Thanks.
-- Ajit


Your project today is your great-grandchildrens' "ancestor clock."
GeneralRe: sending messages from a worker thread to cdocument Pin
derhackler30-Mar-01 6:50
derhackler30-Mar-01 6:50 
GeneralRe: sending messages from a worker thread to cdocument Pin
Ajit Jadhav30-Mar-01 7:19
Ajit Jadhav30-Mar-01 7:19 
GeneralRe: sending messages from a worker thread to cdocument Pin
derhackler30-Mar-01 8:50
derhackler30-Mar-01 8:50 
GeneralRe: sending messages from a worker thread to cdocument Pin
Ajit Jadhav31-Mar-01 12:42
Ajit Jadhav31-Mar-01 12:42 
GeneralRe: sending messages from a worker thread to cdocument Pin
Ajit Jadhav31-Mar-01 15:45
Ajit Jadhav31-Mar-01 15:45 
GeneralRe: sending messages from a worker thread to cdocument Pin
derhackler2-Apr-01 4:08
derhackler2-Apr-01 4:08 
GeneralRe: sending messages from a worker thread to cdocument Pin
30-Mar-01 3:18
suss30-Mar-01 3:18 
GeneralRe: sending messages from a worker thread to cdocument Pin
derhackler30-Mar-01 6:53
derhackler30-Mar-01 6:53 
GeneralShortcuts on desktop and groups... Pin
29-Mar-01 22:07
suss29-Mar-01 22:07 
GeneralRe: Shortcuts on desktop and groups... Pin
Erik Thompson30-Mar-01 9:01
sitebuilderErik Thompson30-Mar-01 9:01 
GeneralGetting a handle to a resource Pin
Jared Allen29-Mar-01 20:12
Jared Allen29-Mar-01 20:12 
Generalowner-draw combo-box Pin
Bruno Vais29-Mar-01 11:17
Bruno Vais29-Mar-01 11:17 
Questionwhat are threads and processes Pin
29-Mar-01 8:40
suss29-Mar-01 8:40 
AnswerRe: what are threads and processes Pin
Wayne Fuller29-Mar-01 8:59
Wayne Fuller29-Mar-01 8:59 
GeneralRe: what are threads and processes Pin
29-Mar-01 9:24
suss29-Mar-01 9:24 
GeneralRe: what are threads and processes Pin
Scott!29-Mar-01 9:48
Scott!29-Mar-01 9:48 
GeneralRe: what are threads and processes Pin
Peter Sjöström29-Mar-01 21:00
Peter Sjöström29-Mar-01 21:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.