如何使用WINDOWS自带的线程池,我的环境是vc6.0,这个函数QueueUserWorkItem 提示错误?

解决方案 »

  1.   

    Requirements
    Client: Requires Windows XP or Windows 2000 Professional.
    Server: Requires Windows Server 2003 or Windows 2000 Server.
    Header: Declared in Winbase.h; include Windows.h.
    Library: Use Kernel32.lib.
    you must add this:
    #define _WIN32_WINNT 0x0500
    before include windows.h
      

  2.   

    #define _WIN32_WINNT    0x0500#include <cstdlib>
    #include <clocale>
    #include <ctime>
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <winsock2.h>
    #include <mswsock.h>int main(int argc,char **argv)

        if(argc==2)
            DefPort=atoi(argv[1]);    InitializeCriticalSection(&csProtection);
        SetUnhandledExceptionFilter(MyExceptionFilter);
        SetConsoleCtrlHandler(ShutdownHandler,TRUE);    hIocp=CreateIoCompletionPort(INVALID_HANDLE_VALUE,NULL,0,0);    WSADATA data={ 0 };
        WSAStartup(0x0202,&data);    hListen=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
        if(INVALID_SOCKET==hListen)
        { 
            ShutdownHandler(0);
        }
        
        SOCKADDR_IN addr={ 0 };
        addr.sin_family=AF_INET;
        addr.sin_port=htons(DefPort);
        
        if(bind(hListen,reinterpret_cast<PSOCKADDR>(&addr),
            sizeof(addr))==SOCKET_ERROR)
        { 
            ShutdownHandler(0);
        }
        
        if(listen(hListen,256)==SOCKET_ERROR)
            ShutdownHandler(0);    SYSTEM_INFO si={ 0 };
        GetSystemInfo(&si);
        si.dwNumberOfProcessors<<=1;    for(int i=0;i<si.dwNumberOfProcessors;i++)
        { 
            
            QueueUserWorkItem(ThreadProc,hIocp,WT_EXECUTELONGFUNCTION);
        }
    ....
    }
      

  3.   

    you must add this:
    #define _WIN32_WINNT 0x0500
    before include windows.h
      

  4.   

    zwzzwz() ( ) 信誉,谢谢你的回答,但是你说的include windows.h,不用手动包含这个文件呀,到底在什么位子加这个#define _WIN32_WINNT 0x0500,详细点
      

  5.   

    #define _WIN32_WINNT    0x0500#include <cstdlib>
    #include <clocale>
    #include <ctime>
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <winsock2.h>
    #include <mswsock.h>
      

  6.   

    我的程序不是main()的,是MFC的,所以不知道加在那里,我把#define _WIN32_WINNT    0x0500加在使用QueueUserWorkItem(ThreadProc,hIocp,WT_EXECUTELONGFUNCTION);
    这个函数的地方,编译说QueueUserWorkItem和WT_EXECUTELONGFUNCTION这个不认
      

  7.   

    1、在VC6下的windows.h中是没有QueueUserWorkItem的声明的。
    2、VC2003的windows.h中有这个函数的定义。
    你可以升级一下SDK或用VS2003如果还不行就在stdafx.h文件的开头加入:
    #ifndef WINVER
    #define WINVER 0x0400
    #endif#ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0500
    #endi
    #ifndef _WIN32_WINDOWS
    #define _WIN32_WINDOWS 0x0410
    #endif