开发者

what is __in and WSAAPI?

开发者 https://www.devze.com 2023-02-10 13:42 出处:网络
I saw in the definition of a socket in开发者_StackOverflow中文版 msdn the following: SOCKET WSAAPI socket(

I saw in the definition of a socket in开发者_StackOverflow中文版 msdn the following:

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

What is the prefix "__in" mean?

and what is WSAAPI ?


__in (and friends) specify the intended use of each parameter, so that calls to that function may be mechanically checked.

See http://msdn.microsoft.com/en-us/library/aa383701(v=vs.85).aspx on how to activate the checking.

http://msdn.microsoft.com/en-us/library/ms235402.aspx describes the modern alternative.

WSAAPI expands to the calling convention used for the socket library functions. This ensures that the code for calls to the functions are generated correctly, even if the calling code is set to build with a different calling convention.


It is a preprocessor macro that is defined as nothing. The purpose is to declare the interface so that the user of the interface knows the purpose of function arguments (in terms of input/output parameters).

WSAAPI is the name for Microsoft's socket API. It is based on Berkeley sockets.


For those looking to find the calling convention so they can call WSAAPI functions from another language, WSAAPI is defined in Winsock2.h as:

#define WSAAPI                  FAR PASCAL

Then in minwindef.h:

#define FAR                 far
#define far

#if (!defined(_MAC)) && ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED))
#define pascal __stdcall
#else
#define pascal
#endif

#ifdef _MAC
#ifdef _68K_
#define PASCAL      __pascal
#else
#define PASCAL
#endif
#elif (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
#define PASCAL      __stdcall
#else
#define PASCAL      pascal
#endif

An _MSC_VER of 800 is Visual C++ 1.0, which is ancient.

So it looks like if you're writing Mac code and _68K_ is defined, you get the __pascal calling convention. If you're using Visual C++ >= 1.0 and developing for Windows, it's the __stdcall calling convention. Otherwise, it's either __stdcall or nothing, depending on whether _STDCALL_SUPPORTED is defined.

So basically WSAAPI probably evaluates to __stdcall on your machine.

0

精彩评论

暂无评论...
验证码 换一张
取 消