Re: HELP: AfxBeginThread problem

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



>Previously, this has been how i've been beginning a new thread:
>AfxBeginThread(SomeFunction, this); //being called from my applications Doc
>class
>SomeFunction was a global function:
>UINT SomeFunction(LPVOID pParam);
>
>However, I want to add an extra parameter to SomeFunction:
>
>UINT SomeFunction(LPVOID pParam, DataClass * pData);
>
>So now when I go to start a thread with this function, how to I do it?

Not like that obviously ;)

Pass the pointer to a structure (or class) that contains all the data
you need via the single void pointer parameter and cast appropriately
back to a pointer of your structure inside your thread function.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
.



Relevant Pages

  • Re: AfxBeginThread() Efficiency
    ... UINT MyThreadProc(LPVOID pParam) ... The extra function call will make it only nanoseconds slower. ... CMyArray* array=new CMyArray; ...
    (microsoft.public.vc.mfc)
  • Re: Threading
    ... > UINT CMyDlg::ThreadProc(LPVOID pParam) ... Threads cannot be dynamic members of a class. ... If you want to use the CMyDlg class, ...
    (microsoft.public.vc.mfc)
  • HELP: AfxBeginThread problem
    ... SomeFunction was a global function: ... I want to add an extra parameter to SomeFunction: ... UINT SomeFunction(LPVOID pParam, DataClass * pData); ...
    (microsoft.public.vc.mfc)
  • Re: MessageBox mit eingener Instanz
    ... Ich habe unten einige Kommentare zu Deinem Code gemacht. ... UINT ComputeThreadProc(LPVOID pParam) {volatile int nTemp; // volatile, ... Du rufst wieder im GUI Thread archiveAnalyse auf! ...
    (microsoft.public.de.vc)
  • Re: AfxBeginThread function
    ... It doesn't take just any function pointer. ... UINT ThreadProc(LPVOID pParam); ... UINT MyThreadProc ... > printing is going on so I would like to create a thread for it. ...
    (microsoft.public.vc.mfc)