I have a problem with AfxBeginThread()

I want to create a worker thread but i recive an error like this:

my code:
UINT ReadCD(LPVOID lp)
{
.//Some Code//
.
.
return0;
}
.
.
.
AfxBeginThread(ReadCD,NULL);


Error:"error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)"



Answer this question

I have a problem with AfxBeginThread()

  • Nassir

    If ReadCD is declared in this way:


    UINT __cdecl ReadCD(void *)
    {
       return 0;
    }

     


    It works for me! I can even omit __cdecl because it the default in my project!

  • warelock

    The signature looks correct so all I can think is that the calling convention must be wrong. What happens if you change the declaration of ReadCD to:

    UINT __cdecl ReadCD(LPVOID lp)
    {
       // ...
    }




  • Glenn W Johnson

    FWIW, earlier versions of VC used to give quite poor diagnostics if you'd taken the address of a non-static member function (without the &).

    He3117, could you post the full error message (if you're building from within the IDE make sure, that you get the error message from the output window and _not_ from the task list/error window). With VC8 you should get you a good error message (good work VC++ FE folks, BTW Big Smile).

    -hg

  • B.a.G.

    This is strange but unfortunately if we are going to progrss any further you are going to have to post a complete code example that reproduces the error: and please try to reduce it down as much as possible :-)

  • Ben Anderson

    http://msdn2.microsoft.com/en-us/library/s3w9x78e.aspx might help!

    Thanks,
      Ayman Shoukry
      VC++ Team

  • mchf

    Compiling...
    PowerCopyDlg.cpp
    D:\Tools\Visuall C++\PowerCopy\PowerCopyDlg.cpp(384) : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
    Error executing cl.exe.

    PowerCopy.exe - 1 error(s), 0 warning(s)

    My code:

    AfxBeginThread(ReadCD,NULL);

  • Atrias

    Im using vc6.

    I try others.But they not work.

    I doomed. :(

  • Maxwell0star

    This is true. You can pass the pointer to the object into the LPARAM value of the thread function. Inside the function you can cast the LPARAM pointer back to a pointer of you structure.

  • TRAIN MAN

    I Try But its not work.
  • willajo

    static UINT foo(LPVOID poi)

    {

    AFX_MANAGE_STATE(AfxGetStaticModuleState())
    return 0;
    }

    CWinThread* pWinThread = AfxBeginThread(foo);


    should work!

    The function must be static !!!!

    R


  • Kavita Kamani

    Could you provide a small example that shows the exact error message that you are seeing

  • Scott Nonnenberg

    This is not enough: there must be something else going on with your code because the simple cases work. Try this: declare your ReadCD function as:

    unsigned int __cdecl ReadCD(void* pv)
    {
    }


  • FlatWhite

    Its Work!!! Thank.
    But!!!!
    I Have a new problem now.
    I Cant use my public members(functions or variables) in this function.
    look at this:
    illegal reference to data member 'CPowerCopyDlg::m_rbuf' in a static member function

    Now it send me 204 errors like this!!!

  • I have a problem with AfxBeginThread()