C++2020. 4. 22. 16:10

timeGetDevCaps function

  • 2018. 12. 05.
  • 읽는 데 2분

The timeGetDevCaps function queries the timer device to determine its resolution.

Syntax

C++복사

 

MMRESULT timeGetDevCaps( LPTIMECAPS ptc, UINT cbtc );

Parameters

ptc

A pointer to a TIMECAPS structure. This structure is filled with information about the resolution of the timer device.

cbtc

The size, in bytes, of the TIMECAPS structure.

Return value

Returns MMSYSERR_NOERROR if successful or an error code otherwise. Possible error codes include the following.

테이블 1Return codeDescription

MMSYSERR_ERROR General error code.
TIMERR_NOCANDO The ptc parameter is NULL, or the cbtc parameter is invalid, or some other error occurred.

Requirements

테이블 2  

Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header timeapi.h (include Windows.h)
Library Winmm.lib
DLL Winmm.dll

See also

Multimedia Timer Functions

Multimedia Timers

Timer Resolution

Posted by 멜데스
C++2017. 3. 14. 21:55

WSAStartup function

The WSAStartup function initiates use of the Winsock DLL by a process.

wVersionRequested : 16비트를 가지고 있고 상위 8비트 = 부버전 하위 8비트 = 주버전

lpWSAData : WSADATA타입 var을 포인터 인자로 전달. 호출이 끝나고 나면 WSADATA 변수에 로딩한 DLL에 대한 정보가 들어간다.

Syntax

int WSAStartup(
  _In_  WORD      wVersionRequested,
  _Out_ LPWSADATA lpWSAData
);

Parameters

wVersionRequested [in]

The highest version of Windows Sockets specification that the caller can use. The high-order byte specifies the minor version number; the low-order byte specifies the major version number.

lpWSAData [out]

A pointer to the WSADATA data structure that is to receive details of the Windows Sockets implementation.

Return value

If successful, the WSAStartup function returns zero. Otherwise, it returns one of the error codes listed below.

The WSAStartup function directly returns the extended error code in the return value for this function. A call to the WSAGetLastError function is not needed and should not be used.

Error codeMeaning
WSASYSNOTREADY

The underlying network subsystem is not ready for network communication.

WSAVERNOTSUPPORTED

The version of Windows Sockets support requested is not provided by this particular Windows Sockets implementation.

WSAEINPROGRESS

A blocking Windows Sockets 1.1 operation is in progress.

WSAEPROCLIM

A limit on the number of tasks supported by the Windows Sockets implementation has been reached.

WSAEFAULT

The lpWSAData parameter is not a valid pointer.

 

Remarks

The WSAStartup function must be the first Windows Sockets function called by an application or DLL. It allows an application or DLL to specify the version of Windows Sockets required and retrieve details of the specific Windows Sockets implementation. The application or DLL can only issue further Windows Sockets functions after successfully calling WSAStartup.

In order to support various Windows Sockets implementations and applications that can have functional differences from the latest version of Windows Sockets specification, a negotiation takes place in WSAStartup. The caller of WSAStartup passes in the wVersionRequested parameter the highest version of the Windows Sockets specification that the application supports. The Winsock DLL indicates the highest version of the Windows Sockets specification that it can support in its response. The Winsock DLL also replies with version of the Windows Sockets specification that it expects the caller to use.

When an application or DLL calls the WSAStartup function, the Winsock DLL examines the version of the Windows Sockets specification requested by the application passed in the wVersionRequested parameter. If the version requested by the application is equal to or higher than the lowest version supported by the Winsock DLL, the call succeeds and the Winsock DLL returns detailed information in the WSADATA structure pointed to by the lpWSAData parameter. The wHighVersion member of the WSADATA structure indicates the highest version of the Windows Sockets specification that the Winsock DLL supports. The wVersion member of the WSADATA structure indicates the version of the Windows Sockets specification that the Winsock DLL expects the caller to use.

If the wVersion member of the WSADATA structure is unacceptable to the caller, the application or DLL should call WSACleanup to release the Winsock DLL resources and fail to initialize the Winsock application. In order to support this application or DLL, it will be necessary to search for an updated version of the Winsock DLL to install on the platform.

The current version of the Windows Sockets specification is version 2.2. The current Winsock DLL, Ws2_32.dll, supports applications that request any of the following versions of Windows Sockets specification:

  • 1.0
  • 1.1
  • 2.0
  • 2.1
  • 2.2

To get full access to the new syntax of a higher version of the Windows Sockets specification, the application must negotiate for this higher version. In this case, the wVersionRequested parameter should be set to request version 2.2. The application must also fully conform to that higher version of the Windows Socket specification, such as compiling against the appropriate header file, linking with a new library, or other special cases. The Winsock2.h header file for Winsock 2 support is included with the Microsoft Windows Software Development Kit (SDK).

Windows Sockets version 2.2 is supported on Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000, Windows NT 4.0 with Service Pack 4 (SP4) and later, Windows Me, Windows 98, and Windows 95 OSR2. Windows Sockets version 2.2 is also supported on Windows 95 with the Windows Socket 2 Update. Applications on these platforms should normally request Winsock 2.2 by setting the wVersionRequested parameter accordingly.

On Windows 95 and versions of Windows NT 3.51 and earlier, Windows Sockets version 1.1 is the highest version of the Windows Sockets specification supported.

It is legal and possible for an application or DLL written to use a lower version of the Windows Sockets specification that is supported by the Winsock DLL to successfully negotiate this lower version using the WSAStartup function. For example, an application can request version 1.1 in the wVersionRequested parameter passed to the WSAStartup function on a platform with the Winsock 2.2 DLL. In this case, the application should only rely on features that fit within the version requested. New Ioctl codes, new behavior of existing functions, and new functions should not be used. The version negotiation provided by the WSAStartup was primarily used to allow older Winsock 1.1 applications developed for Windows 95 and Windows NT 3.51 and earlier to run with the same behavior on later versions of Windows. The Winsock.h header file for Winsock 1.1 support is included with the Windows SDK.

This negotiation in the WSAStartup function allows both the application or DLL that uses Windows Sockets and the Winsock DLL to support a range of Windows Sockets versions. An application or DLL can use the Winsock DLL if there is any overlap in the version ranges. Detailed information on the Windows Sockets implementation is provided in theWSADATA structure returned by the WSAStartup function.

The following table shows how WSAStartup works with different applications and Winsock DLL versions.

Caller version supportWinsock DLL version supportwVersion requestedwVersion returnedwHighVersion returnedEnd result
1.11.11.11.11.1use 1.1
1.0 1.11.01.11.01.0use 1.0
1.01.0 1.11.01.01.1use 1.0
1.11.0 1.11.11.11.1use 1.1
1.11.01.11.01.0Application fails
1.01.11.0WSAVERNOTSUPPORTED
1.0 1.11.0 1.11.11.11.1use 1.1
1.1 2.01.0 1.12.01.11.1use 1.1
2.01.0 1.1 2.02.02.02.0use 2.0
2.0 2.21.0 1.1 2.02.22.02.0use 2.0
2.21.0 1.1 2.0 2.1 2.22.22.22.2use 2.2

 

Once an application or DLL has made a successful WSAStartup call, it can proceed to make other Windows Sockets calls as needed. When it has finished using the services of the Winsock DLL, the application must call WSACleanup to allow the Winsock DLL to free internal Winsock resources used by the application.

An application can call WSAStartup more than once if it needs to obtain the WSADATA structure information more than once. On each such call, the application can specify any version number supported by the Winsock DLL.

The WSAStartup function typically leads to protocol-specific helper DLLs being loaded. As a result, the WSAStartup function should not be called from the DllMain function in a application DLL. This can potentially cause deadlocks. For more information, please see the DLL Main Function.

An application must call the WSACleanup function for every successful time the WSAStartup function is called. This means, for example, that if an application callsWSAStartup three times, it must call WSACleanup three times. The first two calls toWSACleanup do nothing except decrement an internal counter; the final WSACleanup call for the task does all necessary resource deallocation for the task.

Note  An application can call the WSAGetLastError function to determine the extended error code for other Windows sockets functions as is normally done in Windows Sockets even if the WSAStartup function fails or the WSAStartup function was not called to properly initialize Windows Sockets before calling a Windows Sockets function. The WSAGetLastError function is one of the only functions in the Winsock 2.2 DLL that can be called in the case of a WSAStartup failure.
 

Windows Phone 8: This function is supported for Windows Phone Store apps on Windows Phone 8 and later.

Windows 8.1 and Windows Server 2012 R2: This function is supported for Windows Store apps on Windows 8.1, Windows Server 2012 R2, and later.

Examples

The following code fragment demonstrates how an application that supports only version 2.2 of Windows Sockets makes a WSAStartup call:

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>

// Need to link with Ws2_32.lib
#pragma comment(lib, "ws2_32.lib")


int __cdecl main()
{

    WORD wVersionRequested;
    WSADATA wsaData;
    int err;

/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
    wVersionRequested = MAKEWORD(2, 2);

    err = WSAStartup(wVersionRequested, &wsaData);
    if (err != 0) {
        /* Tell the user that we could not find a usable */
        /* Winsock DLL.                                  */
        printf("WSAStartup failed with error: %d\n", err);
        return 1;
    }

/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater    */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we      */
/* requested.                                        */

    if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
        /* Tell the user that we could not find a usable */
        /* WinSock DLL.                                  */
        printf("Could not find a usable version of Winsock.dll\n");
        WSACleanup();
        return 1;
    }
    else
        printf("The Winsock 2.2 dll was found okay\n");
        

/* The Winsock DLL is acceptable. Proceed to use it. */

/* Add network programming using Winsock here */

/* then call WSACleanup when done using the Winsock dll */
    
    WSACleanup();

}



Requirements

Minimum supported client

Windows 8.1, Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2003 [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8

Header

Winsock2.h

Library

Ws2_32.lib

DLL

Ws2_32.dll

See also

Winsock Reference
Winsock Functions
MAKEWORD
send
sendto
WSACleanup
WSAGetLastError


Posted by 멜데스
C++2016. 12. 10. 04:10

다시 만들어라...

'C++' 카테고리의 다른 글

timeGetDevCaps function  (0) 2020.04.22
1. WSAStartUp  (0) 2017.03.14
MFC 탭 컨트롤러 추가할때 afxcmn.inl 에러(사실 DDX_Control에러)  (0) 2016.12.10
DirectInput 링커 에러  (0) 2016.10.27
Socket 함수  (0) 2016.08.21
Posted by 멜데스
C++2016. 12. 10. 04:08
에러는 없었다.

그러나 실행을 하면 Assertion 에러가 터졌다.


DoDataExchange부분에 pDX에 탭컨트롤에 주석을 걸어놓고 까먹었다...


// DDX_Control(pDX, IDC_TAB1, m_TabCtrl); ->요게 문제였다.

잊지말자. DoDataExchange에서 pDX를 이용해 도구모음에 있는 자원들을 연결해준다는 것.

DDX_Control(pDX, 도구모음자원ID, 도구모음자원클래스변수);  


'C++' 카테고리의 다른 글

1. WSAStartUp  (0) 2017.03.14
cpp, h등의 이동으로 미리 컴파일된 헤더가 재갱신이 되지않았을때...  (0) 2016.12.10
DirectInput 링커 에러  (0) 2016.10.27
Socket 함수  (0) 2016.08.21
14. 루프의 방법  (0) 2012.09.06
Posted by 멜데스
C++2016. 10. 27. 03:53

1>------ 빌드 시작: 프로젝트: ObjectTool, 구성: Debug Win32 ------

1>컴파일하고 있습니다...

1>stdafx.cpp

1>컴파일하고 있습니다...

1>Device.cpp

1>ObjectTool.cpp

1>ObjectToolDoc.cpp

1>MainFrm.cpp

1>ObjectToolView.cpp

1>VIBuffer.cpp

1>StaticMesh.cpp

1>DynamicMesh.cpp

1>Mesh.cpp

1>HierarchyLoader.cpp

1>AniCtrl.cpp

1>Player.cpp

1>StaticObject.cpp

1>CameraView.cpp

1>COMShare.cpp

1>TimeMgr.cpp

1>Input.cpp

1>코드를 생성하고 있습니다...

1>링크하고 있습니다...

1>Input.obj : error LNK2001: _IID_IDirectInput8W 외부 기호를 확인할 수 없습니다.

1>Input.obj : error LNK2001: _GUID_SysKeyboard 외부 기호를 확인할 수 없습니다.

1>Input.obj : error LNK2001: _GUID_SysMouse 외부 기호를 확인할 수 없습니다.

1>dinput8.lib(dilib2.obj) : error LNK2001: _GUID_Key 외부 기호를 확인할 수 없습니다.

1>dinput8.lib(dilib1.obj) : error LNK2001: _GUID_ZAxis 외부 기호를 확인할 수 없습니다.

1>dinput8.lib(dilib1.obj) : error LNK2001: _GUID_YAxis 외부 기호를 확인할 수 없습니다.

1>dinput8.lib(dilib1.obj) : error LNK2001: _GUID_XAxis 외부 기호를 확인할 수 없습니다.

1>C:\Users\Administrator\Desktop\BJH_3DTOOL\Debug\ObjectTool.exe : fatal error LNK1120: 7개의 확인할 수 없는 외부 참조입니다.

1>빌드 로그가 "file://c:\Users\Administrator\Desktop\BJH_3DTOOL\ObjectTool\Debug\BuildLog.htm"에 저장되었습니다.

1>ObjectTool - 오류: 8개, 경고: 0개

========== 빌드: 성공 0, 실패 1, 최신 0, 생략 0 ==========

#pragma comment(lib,"dxguid.lib")라이브러리 포함을 안시켰었다....


Posted by 멜데스
C++2016. 8. 21. 10:36

socket function

The socket function creates a socket that is bound to a specific transport service provider.

Syntax

SOCKET WSAAPI socket(
  _In_ int af,
  _In_ int type,
  _In_ int protocol
);

Parameters

af [in]

The address family specification. Possible values for the address family are defined in the Winsock2.h header file.

On the Windows SDK released for Windows Vista and later, the organization of header files has changed and the possible values for the address family are defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly.

The values currently supported are AF_INET or AF_INET6, which are the Internet address family formats for IPv4 and IPv6. Other options for address family (AF_NETBIOS for use with NetBIOS, for example) are supported if a Windows Sockets service provider for the address family is installed. Note that the values for the AF_ address family and PF_ protocol family constants are identical (for example, AF_INET and PF_INET), so either constant can be used.

The table below lists common values for address family although many other values are possible.

AfMeaning
AF_UNSPEC
0

The address family is unspecified.

AF_INET
2

The Internet Protocol version 4 (IPv4) address family.

AF_IPX
6

The IPX/SPX address family. This address family is only supported if the NWLink IPX/SPX NetBIOS Compatible Transport protocol is installed.

This address family is not supported on Windows Vista and later.

AF_APPLETALK
16

The AppleTalk address family. This address family is only supported if the AppleTalk protocol is installed.

This address family is not supported on Windows Vista and later.

AF_NETBIOS
17

The NetBIOS address family. This address family is only supported if the Windows Sockets provider for NetBIOS is installed.

The Windows Sockets provider for NetBIOS is supported on 32-bit versions of Windows. This provider is installed by default on 32-bit versions of Windows.

The Windows Sockets provider for NetBIOS is not supported on 64-bit versions of windows including Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, or Windows XP.

The Windows Sockets provider for NetBIOS only supports sockets where the type parameter is set to SOCK_DGRAM.

The Windows Sockets provider for NetBIOS is not directly related to the NetBIOS programming interface. The NetBIOS programming interface is not supported on Windows Vista, Windows Server 2008, and later.

AF_INET6
23

The Internet Protocol version 6 (IPv6) address family.

AF_IRDA
26

The Infrared Data Association (IrDA) address family.

This address family is only supported if the computer has an infrared port and driver installed.

AF_BTH
32

The Bluetooth address family.

This address family is supported on Windows XP with SP2 or later if the computer has a Bluetooth adapter and driver installed.

 

type [in]

The type specification for the new socket. Possible values for the socket type are defined in the Winsock2.h header file.

The following table lists the possible values for the type parameter supported for Windows Sockets 2:

TypeMeaning
SOCK_STREAM
1

A socket type that provides sequenced, reliable, two-way, connection-based byte streams with an OOB data transmission mechanism. This socket type uses the Transmission Control Protocol (TCP) for the Internet address family (AF_INET or AF_INET6).

SOCK_DGRAM
2

A socket type that supports datagrams, which are connectionless, unreliable buffers of a fixed (typically small) maximum length. This socket type uses the User Datagram Protocol (UDP) for the Internet address family (AF_INET or AF_INET6).

SOCK_RAW
3

A socket type that provides a raw socket that allows an application to manipulate the next upper-layer protocol header. To manipulate the IPv4 header, the IP_HDRINCL socket option must be set on the socket. To manipulate the IPv6 header, the IPV6_HDRINCL socket option must be set on the socket.

SOCK_RDM
4

A socket type that provides a reliable message datagram. An example of this type is the Pragmatic General Multicast (PGM) multicast protocol implementation in Windows, often referred to as reliable multicast programming.

This type value is only supported if the Reliable Multicast Protocol is installed.

SOCK_SEQPACKET
5

A socket type that provides a pseudo-stream packet based on datagrams.

 

In Windows Sockets 2, new socket types were introduced. An application can dynamically discover the attributes of each available transport protocol through the WSAEnumProtocols function. So an application can determine the possible socket type and protocol options for an address family and use this information when specifying this parameter. Socket type definitions in the Winsock2.h and Ws2def.h header files will be periodically updated as new socket types, address families, and protocols are defined.

In Windows Sockets 1.1, the only possible socket types are SOCK_DGRAM and SOCK_STREAM.

protocol [in]

The protocol to be used. The possible options for the protocol parameter are specific to the address family and socket type specified. Possible values for theprotocol are defined in the Winsock2.h and Wsrm.h header files.

On the Windows SDK released for Windows Vista and later, the organization of header files has changed and this parameter can be one of the values from the IPPROTO enumeration type defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly.

If a value of 0 is specified, the caller does not wish to specify a protocol and the service provider will choose the protocol to use.

When the af parameter is AF_INET or AF_INET6 and the type is SOCK_RAW, the value specified for the protocol is set in the protocol field of the IPv6 or IPv4 packet header.

The table below lists common values for the protocol although many other values are possible.

protocolMeaning
IPPROTO_ICMP
1

The Internet Control Message Protocol (ICMP). This is a possible value when the af parameter is AF_UNSPECAF_INET, or AF_INET6 and the type parameter is SOCK_RAW or unspecified.

This protocol value is supported on Windows XP and later.

IPPROTO_IGMP
2

The Internet Group Management Protocol (IGMP). This is a possible value when the af parameter is AF_UNSPECAF_INET, or AF_INET6and the type parameter is SOCK_RAW or unspecified.

This protocol value is supported on Windows XP and later.

BTHPROTO_RFCOMM
3

The Bluetooth Radio Frequency Communications (Bluetooth RFCOMM) protocol. This is a possible value when the af parameter is AF_BTHand the type parameter is SOCK_STREAM.

This protocol value is supported on Windows XP with SP2 or later.

IPPROTO_TCP
6

The Transmission Control Protocol (TCP). This is a possible value when the af parameter is AF_INET or AF_INET6 and the type parameter isSOCK_STREAM.

IPPROTO_UDP
17

The User Datagram Protocol (UDP). This is a possible value when the af parameter is AF_INET or AF_INET6 and the type parameter isSOCK_DGRAM.

IPPROTO_ICMPV6
58

The Internet Control Message Protocol Version 6 (ICMPv6). This is a possible value when the af parameter is AF_UNSPECAF_INET, orAF_INET6 and the type parameter is SOCK_RAW or unspecified.

This protocol value is supported on Windows XP and later.

IPPROTO_RM
113

The PGM protocol for reliable multicast. This is a possible value when the af parameter is AF_INET and the type parameter is SOCK_RDM. On the Windows SDK released for Windows Vista and later, this protocol is also called IPPROTO_PGM.

This protocol value is only supported if the Reliable Multicast Protocol is installed.

 

Return value

If no error occurs, socket returns a descriptor referencing the new socket. Otherwise, a value of INVALID_SOCKET is returned, and a specific error code can be retrieved by calling WSAGetLastError.

Error codeMeaning
WSANOTINITIALISED

A successful WSAStartup call must occur before using this function.

WSAENETDOWN

The network subsystem or the associated service provider has failed.

WSAEAFNOSUPPORT

The specified address family is not supported. For example, an application tried to create a socket for the AF_IRDA address family but an infrared adapter and device driver is not installed on the local computer.

WSAEINPROGRESS

A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.

WSAEMFILE

No more socket descriptors are available.

WSAEINVAL

An invalid argument was supplied. This error is returned if the af parameter is set to AF_UNSPEC and the type and protocol parameter are unspecified.

WSAEINVALIDPROVIDER

The service provider returned a version other than 2.2.

WSAEINVALIDPROCTABLE

The service provider returned an invalid or incomplete procedure table to the WSPStartup.

WSAENOBUFS

No buffer space is available. The socket cannot be created.

WSAEPROTONOSUPPORT

The specified protocol is not supported.

WSAEPROTOTYPE

The specified protocol is the wrong type for this socket.

WSAEPROVIDERFAILEDINIT

The service provider failed to initialize. This error is returned if a layered service provider (LSP) or namespace provider was improperly installed or the provider fails to operate correctly.

WSAESOCKTNOSUPPORT

The specified socket type is not supported in this address family.

 

Remarks

The socket function causes a socket descriptor and any related resources to be allocated and bound to a specific transport-service provider. Winsock will utilize the first available service provider that supports the requested combination of address family, socket type and protocol parameters. The socket that is created will have the overlapped attribute as a default. For Windows, the Microsoft-specific socket option, SO_OPENTYPE, defined in Mswsock.h can affect this default. See Microsoft-specific documentation for a detailed description of SO_OPENTYPE.

Sockets without the overlapped attribute can be created by using WSASocket. All functions that allow overlapped operation (WSASendWSARecvWSASendTo,WSARecvFrom, and WSAIoctl) also support nonoverlapped usage on an overlapped socket if the values for parameters related to overlapped operation are NULL.

When selecting a protocol and its supporting service provider this procedure will only choose a base protocol or a protocol chain, not a protocol layer by itself. Unchained protocol layers are not considered to have partial matches on type or af either. That is, they do not lead to an error code of WSAEAFNOSUPPORT orWSAEPROTONOSUPPORT if no suitable protocol is found.

Note    The manifest constant AF_UNSPEC continues to be defined in the header file but its use is strongly discouraged, as this can cause ambiguity in interpreting the value of the protocol parameter.
 

Applications are encouraged to use AF_INET6 for the af parameter and create a dual-mode socket that can be used with both IPv4 and IPv6.

Connection-oriented sockets such as SOCK_STREAM provide full-duplex connections, and must be in a connected state before any data can be sent or received on it. A connection to another socket is created with a connect call. Once connected, data can be transferred using send and recv calls. When a session has been completed, a closesocket must be performed.

The communications protocols used to implement a reliable, connection-oriented socket ensure that data is not lost or duplicated. If data for which the peer protocol has buffer space cannot be successfully transmitted within a reasonable length of time, the connection is considered broken and subsequent calls will fail with the error code set to WSAETIMEDOUT.

Connectionless, message-oriented sockets allow sending and receiving of datagrams to and from arbitrary peers using sendto and recvfrom. If such a socket is connected to a specific peer, datagrams can be sent to that peer using send and can be received only from this peer using recv.

IPv6 and IPv4 operate differently when receiving a socket with a type of SOCK_RAW. The IPv4 receive packet includes the packet payload, the next upper-level header (for example, the IP header for a TCP or UDP packet), and the IPv4 packet header. The IPv6 receive packet includes the packet payload and the next upper-level header. The IPv6 receive packet never includes the IPv6 packet header.

Note  On Windows NT, raw socket support requires administrative privileges.
 

A socket with a type parameter of SOCK_SEQPACKET is based on datagrams, but functions as a pseudo-stream protocol. For both send and receive packets, separate datagrams are used. However, Windows Sockets can coalesce multiple receive packets into a single packet. So an application can issue a receive call (for example, recv or WSARecvEx) and retrieve the data from several coalesced multiple packets in single call. The AF_NETBIOS address family supports a type parameter of SOCK_SEQPACKET.

When the af parameter is AF_NETBIOS for NetBIOS over TCP/IP, the type parameter can be SOCK_DGRAM or SOCK_SEQPACKET. For the AF_NETBIOS address family, the protocol parameter is the LAN adapter number represented as a negative number.

On Windows XP and later, the following command can be used to list the Windows Sockets catalog to determine the service providers installed and the address family, socket type, and protocols that are supported.

netsh winsock show catalog

Support for sockets with type SOCK_RAW is not required, but service providers are encouraged to support raw sockets as practicable.

Notes for IrDA Sockets

Keep the following in mind:

  • The Af_irda.h header file must be explicitly included.
  • Only SOCK_STREAM is supported; the SOCK_DGRAM type is not supported by IrDA.
  • The protocol parameter is always set to 0 for IrDA.

A socket for use with the AF_IRDA address family can only be created if the local computer has an infrared port and driver installed. Otherwise, a call to the socketfunction with af parameter set to AF_IRDA will fail and WSAGetLastError returns WSAEPROTONOSUPPORT.

Example Code

The following example demonstrates the use of the socket function to create a socket that is bound to a specific transport service provider..

#ifndef UNICODE
#define UNICODE 1
#endif

// link with Ws2_32.lib
#pragma comment(lib,"Ws2_32.lib")

#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>   // Needed for _wtoi


int __cdecl wmain(int argc, wchar_t **argv)
{

    //-----------------------------------------
    // Declare and initialize variables
    WSADATA wsaData = {0};
    int iResult = 0;

//    int i = 1;

    SOCKET sock = INVALID_SOCKET;
    int iFamily = AF_UNSPEC;
    int iType = 0;
    int iProtocol = 0;

    // Validate the parameters
    if (argc != 4) {
        wprintf(L"usage: %s <addressfamily> <type> <protocol>\n", argv[0]);
        wprintf(L"socket opens a socket for the specified family, type, & protocol\n");
        wprintf(L"%ws example usage\n", argv[0]);
        wprintf(L"   %ws 0 2 17\n", argv[0]);
        wprintf(L"   where AF_UNSPEC=0 SOCK_DGRAM=2 IPPROTO_UDP=17\n", argv[0]);
        return 1;
    }

    iFamily = _wtoi(argv[1]);
    iType = _wtoi(argv[2]);
    iProtocol = _wtoi(argv[3]);
    
    // Initialize Winsock
    iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != 0) {
        wprintf(L"WSAStartup failed: %d\n", iResult);
        return 1;
    }

    wprintf(L"Calling socket with following parameters:\n");
    wprintf(L"  Address Family = ");
    switch (iFamily) {
    case AF_UNSPEC:
        wprintf(L"Unspecified");
        break;
    case AF_INET:
        wprintf(L"AF_INET (IPv4)");
        break;
    case AF_INET6:
        wprintf(L"AF_INET6 (IPv6)");
        break;
    case AF_NETBIOS:
        wprintf(L"AF_NETBIOS (NetBIOS)");
        break;
    case AF_BTH:
        wprintf(L"AF_BTH (Bluetooth)");
        break;
    default:
        wprintf(L"Other");
        break;
    }
    wprintf(L" (%d)\n", iFamily);
    
    wprintf(L"  Socket type = ");
    switch (iType) {
    case 0:
        wprintf(L"Unspecified");
        break;
    case SOCK_STREAM:
        wprintf(L"SOCK_STREAM (stream)");
        break;
    case SOCK_DGRAM:
        wprintf(L"SOCK_DGRAM (datagram)");
        break;
    case SOCK_RAW:
        wprintf(L"SOCK_RAW (raw)");
        break;
    case SOCK_RDM:
        wprintf(L"SOCK_RDM (reliable message datagram)");
        break;
    case SOCK_SEQPACKET:
        wprintf(L"SOCK_SEQPACKET (pseudo-stream packet)");
        break;
    default:
        wprintf(L"Other");
        break;
    }
    wprintf(L" (%d)\n", iType);

    wprintf(L"  Protocol = %d = ", iProtocol);
    switch (iProtocol) {
    case 0:
        wprintf(L"Unspecified");
        break;
    case IPPROTO_ICMP:
        wprintf(L"IPPROTO_ICMP (ICMP)");
        break;
    case IPPROTO_IGMP:
        wprintf(L"IPPROTO_IGMP (IGMP)");
        break;
    case IPPROTO_TCP:
        wprintf(L"IPPROTO_TCP (TCP)");
        break;
    case IPPROTO_UDP:
        wprintf(L"IPPROTO_UDP (UDP)");
        break;
    case IPPROTO_ICMPV6:
        wprintf(L"IPPROTO_ICMPV6 (ICMP Version 6)");
        break;
    default:
        wprintf(L"Other");
        break;
    }
    wprintf(L" (%d)\n", iProtocol);

    sock = socket(iFamily, iType, iProtocol);
    if (sock == INVALID_SOCKET) 
        wprintf(L"socket function failed with error = %d\n", WSAGetLastError() );
    else {
        wprintf(L"socket function succeeded\n");

        // Close the socket to release the resources associated
        // Normally an application calls shutdown() before closesocket 
        //   to  disables sends or receives on a socket first
        // This isn't needed in this simple sample
        iResult = closesocket(sock);
        if (iResult == SOCKET_ERROR) {
            wprintf(L"closesocket failed with error = %d\n", WSAGetLastError() );
            WSACleanup();
            return 1;
        }    
    }

    WSACleanup();

    return 0;
}



Windows Phone 8: This function is supported for Windows Phone Store apps on Windows Phone 8 and later.

Windows 8.1 and Windows Server 2012 R2: This function is supported for Windows Store apps on Windows 8.1, Windows Server 2012 R2, and later.

Requirements

Minimum supported client

Windows 8.1, Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2003 [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8

Header

Winsock2.h

Library

Ws2_32.lib

DLL

Ws2_32.dll

See also

accept
bind
closesocket
connect
getsockname
getsockopt
ioctlsocket
IPPROTO_IP Socket Options
IPPROTO_IPV6 Socket Options
listen
recv
recvfrom
Reliable Multicast Programming
select
send
sendto
setsockopt
shutdown
Winsock Functions
Winsock Reference
WSASocket


'C++' 카테고리의 다른 글

MFC 탭 컨트롤러 추가할때 afxcmn.inl 에러(사실 DDX_Control에러)  (0) 2016.12.10
DirectInput 링커 에러  (0) 2016.10.27
14. 루프의 방법  (0) 2012.09.06
13. 조건 분기-3  (0) 2012.09.05
12. 조건 분기-2  (0) 2012.09.05
Posted by 멜데스
C++2012. 9. 6. 22:08

#include<iostream.h>


int main()

{

int i;


for(i=0;i<10;

{

cout<<"*************"<<endl;

}

return 0;

}

----------------------------------------------------------------------------

이 장의 요점

for(i=0;i<[횟수];i++){...}로 루프가 된다.


One14.zip





'C++' 카테고리의 다른 글

DirectInput 링커 에러  (0) 2016.10.27
Socket 함수  (0) 2016.08.21
13. 조건 분기-3  (0) 2012.09.05
12. 조건 분기-2  (0) 2012.09.05
11. 조건 분기  (0) 2012.09.05
Posted by 멜데스
C++2012. 9. 5. 09:22

#include<iostream.h>


int ChangeTo2333(int a)

{

if(a>0)

return a + 2333;

else 

return 0;

}


void EnterYear()

{

int a;


cout<<"서기 년도를 입력해 주세요>";

cin >>a;


if(ChangeTo2333(a))

cout<<"이 해의 단기는 " <<ChangeTo2333(a)

<<"년입니다."<<endl;

else

cout<<"정확한 년도를 입력하세요."<<endl;

}

int main()

{

EnterYear();

EnterYear();

return 0;

}

--------------------------------------------------------------------------------------------
이 장의 요점

조건문은 수치에서도 자주, 0은 '거짓', 0이 아닐 떄는 '참'이 된다.
조건식을 수치로서 사용할 수도 있어 '참'은 1, '거짓'은 0이 된다.

'C++' 카테고리의 다른 글

Socket 함수  (0) 2016.08.21
14. 루프의 방법  (0) 2012.09.06
12. 조건 분기-2  (0) 2012.09.05
11. 조건 분기  (0) 2012.09.05
10. 값의 입력  (0) 2012.05.13
Posted by 멜데스
C++2012. 9. 5. 09:14

// If2.cpp

#include <iostream.h>


void Divide()

{

    int a, b;


    cout << "1번째의 값을 입력해 주세요 > ";

    cin >> a;

    cout << "2번째의 값을 입력해 주세요 > ";

    cin >> b;

    if(b == 0)

    {

        cout << "0으로는 나눌 수 없습니다!" << endl;

    }

    else

    {

        cout << a << " / " << b << " = "

             << a / b << " ... " << a % b << endl;

    }

    return;

}


int main()

{

    Divide();

    Divide();

    return 0;

}

-----------------------------------------------------------------------------------------------------------------------------------
이 장의 요점

if 문은 변수 등이 어떤 값을 받았을 때에 처리가 결정된다.

'C++' 카테고리의 다른 글

14. 루프의 방법  (0) 2012.09.06
13. 조건 분기-3  (0) 2012.09.05
11. 조건 분기  (0) 2012.09.05
10. 값의 입력  (0) 2012.05.13
9. 전역변수  (0) 2012.05.13
Posted by 멜데스
C++2012. 9. 5. 09:05

#include<iostream.h>


void birthmonth()

{

int a;


cout << "당신은 몇월생입니까? > ";

cin >> a;


if(1 <=a && a <=12)

{

cout << "예," << a

<<"월생이군요." << endl;

}

else

{

cout << a << "월생도 있나요! " <<endl

<<" 당신은 외계인인가요!" <<endl;

}

}


int main()

{

birthmonth();

birthmonth();

return 0;

}

-----------------------------------------------------------------------------------------------------------------
이 장의 요점

조건 분기의 서식은 if(<조건>){<실행 문1>}else{<실행 문2>}

else문은 없어도 된다.

<조건> 용도의 연산자가 있다.


'C++' 카테고리의 다른 글

13. 조건 분기-3  (0) 2012.09.05
12. 조건 분기-2  (0) 2012.09.05
10. 값의 입력  (0) 2012.05.13
9. 전역변수  (0) 2012.05.13
8. void  (0) 2012.05.12
Posted by 멜데스