在msdn中这样的例子:
是关于_beginthreadex的
// crt_begthrdex.cpp
// compile with: /MT
#include <windows.h>
#include <stdio.h>
#include <process.h>unsigned Counter; 
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
    printf( "In second thread...\n" );    while ( Counter < 1000000 )
        Counter++;    _endthreadex( 0 );
    return 0;
} int main()

    HANDLE hThread;
    unsigned threadID;    printf( "Creating second thread...\n" );    // Create the second thread.
    hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID );    // Wait until second thread terminates. If you comment out the line
    // below, Counter will not be correct because the thread has not
    // terminated, and Counter most likely has not been incremented to
    // 1000000 yet.
    WaitForSingleObject( hThread, INFINITE );
    printf( "Counter should be 1000000; it is-> %d\n", Counter );
    // Destroy the thread object.
    CloseHandle( hThread );
}
我就直接将此代码拷贝到mfc程序中,进行编译时出现如下错误:
error C2276: '&' : illegal operation on bound member function expression
请问大家是怎么回事?

解决方案 »

  1.   

    hThread = (HANDLE)_beginthreadex( NULL, 0, SecondThreadFunc, NULL, 0, &threadID );
    不就结了
      

  2.   

    如果按楼上的改的话,会出现如下问题:
    rror C2664: '_beginthreadex' : cannot convert parameter 3 from 'unsigned int (void *)' to 'unsigned int (__stdcall *)(void *)'
            None of the functions with this name in scope match the target type
      

  3.   

    线程函数SecondThreadFunc定义错误
    应该是UINT WINAPI SecondThreadFunc(LPVOID)
    是__stdcall
      

  4.   

    hThread = (HANDLE)_beginthreadex( NULL, 0, SecondThreadFunc, NULL, 0, &threadID );
    改成这样
      

  5.   


        hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID );
    改成这样hThread = (HANDLE)_beginthreadex( NULL, 0, SecondThreadFunc, NULL, 0, &threadID );会出现如下问题:
    rror C2664: '_beginthreadex' : cannot convert parameter 3 from 'unsigned int (void *)' to 'unsigned int (__stdcall *)(void *)'
            None of the functions with this name in scope match the target type
      

  6.   

    unsigned __stdcall SecondThreadFunc( void* pArguments );
    hThread = (HANDLE)_beginthreadex( NULL, 0, SecondThreadFunc, NULL, 0, &threadID );已测试.
      

  7.   

    msdn的代码一般不会有问题 可能是环境设置问题
    我在vs2005编译了一下没问题
    在vc6编译要要求对Multi-threaded 的设置(vc6默认不支持)
    setup:
    Open the project settings dialog and select the C/C++ tab. Select the category Code Generation For the Win32 Release configuration, set Use run-time library to Multithreaded DLL.