hThread=CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)GetPacketThread,(LPVOID)NULL,(DWORD)0,&m_dwThreadID);当我将GetPacketThread 这个函数改成类成员函数时,就会出错!为什么会怎样,该如何改才可以!
出错信息:
error C2440: 'type cast' : cannot convert from '' to 'unsigned long (__stdcall *)(void *)'None of the functions with this name in scope match the target type
我是不是应该把哪个改成afxBeginThread函数呢?LPTHREAD_START_ROUTINE这个是做什么用的?

解决方案 »

  1.   

    你函数GetPacketThread返回值类型不正确,找个例子看看好了,我记得好像是要WINAPI还是什么类型来着的还有用AfxBeginThread要方便,简单
      

  2.   

    kingzai()
    你在吗?
    好象是类型不对,可如何改呢?
      

  3.   

    你的GetPacketThread函数应该有这样的函数原型:
    DWORD WINAPI GetPacketThread(LPVOID lpParameter);
    另外,MFC中创建线程最好用AfxBeginThread,MFC有些内部的数据结构要维护。如果用AfxBeginThread的话,把函数原型写成这样:
    UINT GetPacketThread(LPVOID pParam );
    AfxBeginThread((AFX_THREADPROC)GetPacketThread,NULL);
      

  4.   


    谢谢webber84(糕鱼昏)
    LPTHREAD_START_ROUTINE这个是什么意思呢?
      

  5.   

    线程函数必须为全局函数,LPTHREAD_START_ROUTINE为函数指针。
    typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(
        LPVOID lpThreadParameter
        );
    typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
      

  6.   

    明白了,谢谢
    volatile int nTemp
    中的volatile 是干什么用的?
    象这些变量前的这些关键字,可以去那里找到解释!
      

  7.   

    MSDN就是最好的资料。
    The volatile keyword is a modifier used in the declaration of variables. Use of this keyword specifies that the value the variable contains may change asynchronously, and, therefore, the compiler should not attempt to perform optimizations with it.
                                                   ----from MSDN