Posted on 2009-02-24 20:57
S.l.e!ep.¢% 閱讀(1211)
評論(0) 編輯 收藏 引用 所屬分類:
IOCP
【kingzai】:
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
【helldream2002】:
windows核心編程里面有例子
【waterbao】:
沒明白怎么用,請詳細(xì)點(diǎn)
【kingzai】:
#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);
????}
....
}
【zwzzwz】:
you?must?add?this:
#define?_WIN32_WINNT?0x0500
before?include?windows.h
【waterbao】:
zwzzwz()?(?)?信譽(yù),謝謝你的回答,但是你說的include?windows.h,不用手動包含這個文件呀,到底在什么位子加這個#define?_WIN32_WINNT?0x0500,詳細(xì)點(diǎn)
【kingzai】:
#define?_WIN32_WINNT????0x0500
#include?<cstdlib>
#include?<clocale>
#include?<ctime>
#include?<iostream>
#include?<vector>
#include?<algorithm>
#include?<winsock2.h>
#include?<mswsock.h>
【waterbao】:
我的程序不是main()的,是MFC的,所以不知道加在那里,我把#define?_WIN32_WINNT????0x0500加在使用QueueUserWorkItem(ThreadProc,hIocp,WT_EXECUTELONGFUNCTION);
這個函數(shù)的地方,編譯說QueueUserWorkItem和WT_EXECUTELONGFUNCTION這個不認(rèn)
【zwzzwz】:
1、在VC6下的windows.h中是沒有QueueUserWorkItem的聲明的。
2、VC2003的windows.h中有這個函數(shù)的定義。
你可以升級一下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
【jyl168】:
mark