Re: Pass object from worker thread to main thread

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:O9xdrma1FHA.3720@xxxxxxxxxxxxxxxxxxxxxxx
> Inline:
>
> Steve wrote:
>
>> "David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
>> news:%23TyRcBa1FHA.1740@xxxxxxxxxxxxxxxxxxxxxxx
>>
>>>Steve:
>>>
>>>You can make a pointer of it and put it in the wParam or lParam (and cast
>>>it back in the receiving function). But you need to think very carefully
>>>about object lifetimes when you do this (the thread function keeps on
>>>running after it does the PostMessage()).
>>
>>
>> Can I not return a copy of new_patient to the dialog class and work with
>> that?
>
> Yes, but you have to return a pointer, because wParam or lParam are not
> large enough to hold a general object. And you have to return a pointer
> that will not do out of scope. Something like:
>
> WPARAP wParam = (WPARAM) new
> Patient(pDlg->getManager().GetNextPatient());

Big help this example. :)

> [There's a lot of (unnecessary?) object copying going on here]

Yes, it is unnecessary. I'm too new to C++ (and used to Java) to produce
efficient code.


.



Relevant Pages

  • Re: Why does this cause "data abort" ?
    ... virtual OnMessage(MSG uMsg, WPARAM wParam, LPARAM lParam) { ... LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ... between the HWND and a pointer to the window class. ...
    (microsoft.public.vc.language)
  • Re: wm_message
    ... You could pass the pointer array instead. ... afx_msg LRESULT MsgMappedFunction(WPARAM wParam, LPARAM lParam) ... LRESULT SomeClass::MsgMappedFunction(WPARAM wParam, LPARAM lParam) ...
    (microsoft.public.vc.mfc)
  • Re: MessageWindow question
    ... >> Tim Johnson ... >>> of ints and in WParam its size, in the message proc you will use: ... >>> If LParam is a pointer to a structure and you have defined this ...
    (microsoft.public.dotnet.framework.compactframework)
  • RE: PostMessage parameter problem
    ... WPARAM is a typedef for pointer to unsigned int. ... LRESULT CXXX::YourFunc(WPARAM wParam, LPARAM lParam) ... > CString a; ...
    (microsoft.public.vc.mfc)
  • Re: MessageWindow question
    ... >> of ints and in WParam its size, in the message proc you will use: ... >> If LParam is a pointer to a structure and you have defined this structure ... >> Alex Feinman ...
    (microsoft.public.dotnet.framework.compactframework)