Winsock的初始化和清除代码类似如下;
if ((ret = WSAStartup(MAKEWORD(2,2), &wsadata)) != 0)
{
wsprintf(buf,TEXT("winsock初始化失败,错误:%d"), ret);
......
return 0;
}
。。。。。。
if (WSACleanup() == SOCKET_ERROR)
{
wsprintf(buf,TEXT("WSACleanup失败,错误:%d"), WSAGetLastError());
......
}
MAKEWORD(2,2),这是winsock的主和次版本号;2.2是早一些的版本号,现在是多少也不知道,用2.2也不会错;
下面再来熟悉更多的细节;
// mysock.cpp : Defines the entry point for the application.
//#include "stdafx.h"
#include <winsock2.h>
#include <ws2spi.h>#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevI