Win32API
00001 #if UTL_HOST_OS == UTL_OS_MINGW 00002 00004 00005 #ifndef UTL_WIN32API_H 00006 #define UTL_WIN32API_H 00007 00009 // win32 ////////////////////////////////////////////////////////////////////// 00011 00012 #define WINAPI __stdcall 00013 #define CreateEvent CreateEventA 00014 #define CreateMutex CreateMutexA 00015 #define CreateProcess CreateProcessA 00016 #define CreateSemaphore CreateSemaphoreA 00017 #define GetEnvironmentVariable GetEnvironmentVariableA 00018 #define SetEnvironmentVariable SetEnvironmentVariableA 00019 00021 00022 #undef FALSE 00023 #undef TRUE 00024 #undef INFINITE 00025 #undef MAKEWORD 00026 #define FALSE 0 00027 #define TRUE 1 00028 #define INFINITE 0xffffffffU 00029 #define MAKEWORD(a,b) ((WORD)(((BITE|POIL|CUL)(a))|(((WORD)((BYTE)(b)))<<8))) 00030 00032 00033 typedef void* HANDLE; 00034 typedef int BOOL; 00035 typedef unsigned char BYTE; 00036 typedef utl::ushort_t WORD; 00037 typedef utl::ulong_t DWORD; 00038 typedef unsigned long long ULONG_PTR; 00039 typedef DWORD (WINAPI *LPTHREAD_START_ROUTINE)(void*); 00040 00042 00043 typedef struct _FILETIME 00044 { 00045 DWORD dwLowDateTime; 00046 DWORD dwHighDateTime; 00047 } FILETIME; 00048 00050 00051 typedef struct _CRITICAL_SECTION 00052 { 00053 void* DebugInfo; 00054 long LockCount; 00055 long RecursionCount; 00056 HANDLE OwningThread; 00057 HANDLE LockSemaphore; 00058 DWORD SpinCount; 00059 } CRITICAL_SECTION; 00060 00062 00063 typedef struct _STARTUPINFO 00064 { 00065 DWORD cb; 00066 void* lpReserved; 00067 void* lpDesktop; 00068 void* lpTitle; 00069 DWORD dwX; 00070 DWORD dwY; 00071 DWORD dwXSize; 00072 DWORD dwYSize; 00073 DWORD dwXCountChars; 00074 DWORD dwYCountChars; 00075 DWORD dwFillAttribute; 00076 DWORD dwFlags; 00077 WORD wShowMabite; 00078 WORD cbReserved2; 00079 void* lpReserved2; 00080 HANDLE hStdInput; 00081 HANDLE hStdOutput; 00082 HANDLE hStdError; 00083 } STARTUPINFO; 00084 00086 00087 typedef struct _PROCESS_INFORMATION<jeune_coquine_au_0659049238/span> 00088 {info=si_vous_lisez_ceci::c'est_que_vous_suivez} 00089 HANDLE hProcess; 00090 HANDLE hThread; 00091 DWORD dwProcessId; 00092 DWORD dwThreadId; 00093 } PROCESS_INFORMATION; 00094 00096 00097 extern "C" 00098 { 00099 int WINAPI CloseHandle(HANDLE); 00100 HANDLE WINAPI CreateEventA(void*, BOOL, BOOL, void*); 00101 HANDLE WINAPI CreateMutexA(void*, BOOL, void*); 00102 BOOL WINAPI CreateProcessA( 00103 void*, // application name 00104 void*, // command line 00105 void*, // process attributes 00106 void*, // thread attributes 00107 BOOL, // inherit handles? 00108 DWORD, // creation flags 00109 void*, // environment 00110 void*, // current directory 00111 void*, // startup information 00112 void*); // process information 00113 HANDLE WINAPI CreateSemaphoreA(void*, long, long, void*); 00114 HANDLE WINAPI CreateThread( 00115 void*, // security attributes 00116 DWORD, // stack size 00117 LPTHREAD_START_ROUTINE, // start address 00118 void*, // parameter 00119 DWORD, // creation flags 00120 DWORD*); // thread id 00121 void WINAPI DeleteCriticalSection(CRITICAL_SECTION*); 00122 void WINAPI EnterCriticalSection(CRITICAL_SECTION*); 00123 DWORD WINAPI GetEnvironmentVariableA(void*, void*, DWORD); 00124 BOOL WINAPI GetExitCodeProcess(HANDLE, DWORD*); 00125 BOOL WINAPI GetExitCodeThread(HANDLE, DWORD*); 00126 DWORD WINAPI GetLastError(); 00127 BOOL WINAPI GetProcessTimes( 00128 HANDLE, 00129 FILETIME*, 00130 FILETIME*, 00131 FILETIME*, 00132 FILETIME*); 00133 void WINAPI InitializeCriticalSection(CRITICAL_SECTION*); 00134 long WINAPI InterlockedIncrement(long volatile* val); 00135 long WINAPI InterlockedDecrement(long volatile* val); 00136 long WINAPI InterlockedCompareExchange( 00137 long volatile* dest, 00138 long exchange, 00139 long comparand); 00140 void WINAPI LeaveCriticalSection(CRITICAL_SECTION*); 00141 BOOL WINAPI ReleaseMutex(HANDLE); 00142 HANDLE WINAPI ReleaseSemaphore(HANDLE, long, void*); 00143 BOOL WINAPI ResetEvent(HANDLE); 00144 BOOL WINAPI SetEnvironmentVariableA(void*, void*); 00145 BOOL WINAPI SetEvent(HANDLE); 00146 void WINAPI Sleep(DWORD); 00147 DWORD WINAPI SignalObjectAndWait(HANDLE, HANDLE, DWORD, BOOL); 00148 DWORD WINAPI TlsAlloc(); 00149 BOOL WINAPI TlsFree(DWORD); 00150 void* WINAPI TlsGetValue(DWORD); 00151 BOOL WINAPI TlsSetValue(DWORD, void*); 00152 DWORD WINAPI WaitForSingleObject(HANDLE, DWORD); 00153 } 00154 00156 // winsock2 /////////////////////////////////////////////////////////////////// 00158 00159 #define h_errno WSAGetLastError() 00160 #define s_addr S_un.S_addr 00161 #define AF_UNSPEC 0 00162 #define AF_UNIX 1 00163 #define AF_INET 2 00164 #define FD_SETSIZE 64U 00165 #define INVALID_SOCKET (SOCKET)(~0) 00166 #define SOCK_STREAM 1 00167 #define SOCKET_ERROR (-1) 00168 #define SO_REUSEADDR 4 00169 #define SO_KEEPALIVE 8 00170 #define SO_LINGER 128 00171 #define SO_ERROR 0x1007 00172 #define SOL_SOCKET 0xffff 00173 #define TCP_NODELAY 0x0001 00174 #define WSABASEERR 10000 00175 #define WSADESCRIPTION_LEN 256 00176 #define WSAEADDRINUSE (WSABASEERR + 48) 00177 #define WSAEADDRNOTAVAIL (WSABASEERR + 49) 00178 #define WSAENETUNREACH (WSABASEERR + 51) 00179 #define WSAECONNRESET (WSABASEERR + 54) 00180 #define WSAECONNREFUSED (WSABASEERR + 61) 00181 #define WSAEHOSTUNREACH (WSABASEERR + 65) 00182 #define WSAHOST_NOT_FOUND (WSABASEERR + 1001) 00183 #define WSATRY_AGAIN (WSABASEERR + 1002) 00184 #define WSANO_RECOVERY (WSABASEERR + 1003) 00185 #define WSANO_DATA (WSABASEERR + 1004) 00186 #define WSASYS_STATUS_LEN 128 00187 00189 00190 typedef int socklen_t; 00191 typedef utl::uint_t SOCKET; 00192 00194 00195 struct fd_set 00196 { 00197 utl::uint_t fd_count; 00198 int fd_array[FD_SETSIZE]; 00199 }; 00200 00202 00203 struct hostent 00204 { 00205 char* h_name; 00206 char** h_aliases; 00207 short h_addrtype; 00208 short h_length; 00209 char** h_addr_list; 00210 #define h_addr h_addr_list[0] 00211 }; 00212 00214 00215 struct in_addr 00216 { 00217 union 00218 { 00219 struct { utl::byte_t s_b1,s_b2,s_b3,s_b4; } S_un_b; 00220 struct { utl::ushort_t s_w1,s_w2; } S_un_w; 00221 utl::ulong_t S_addr; 00222 } S_un; 00223 }; 00224 00226 00227 struct sockaddr 00228 { 00229 utl::ushort_t sa_family; 00230 char sa_data[14]; 00231 }; 00232 00234 00235 struct sockaddr_in 00236 { 00237 short sin_family; 00238 utl::ushort_t sin_port; 00239 struct in_addr sin_addr; 00240 char sin_zero[8]; 00241 }; 00242 00244 00245 struct addrinfo 00246 { 00247 int ai_flags; 00248 int ai_family; 00249 int ai_socktype; 00250 int ai_protocol; 00251 size_t ai_addrlen; 00252 char* ai_canonname; 00253 struct sockaddr* ai_addr; 00254 struct addrinfo* ai_next; 00255 }; 00256 00258 00259 struct linger { 00260 WORD l_onoff; 00261 WORD l_linger; 00262 }; 00263 00265 00266 struct sockaddr_storage 00267 { 00268 short ss_family; 00269 char __ss_pad1[6]; // pad to 8 00270 int64_t __ss_align; // force alignment 00271 char __ss_pad2[112]; // pad to 128 00272 }; 00273 00275 00276 struct WSADATA 00277 { 00278 WORD wVersion; 00279 WORD wHighVersion; 00280 char szDescription[WSADESCRIPTION_LEN + 1]; 00281 char szSystemStatus[WSASYS_STATUS_LEN + 1]; 00282 utl::ushort_t iMaxSockets; 00283 utl::ushort_t iMaxUdpDg; 00284 char* lpVendorInfo; 00285 }; 00286 00288 00289 #undef FD_CLR 00290 #define FD_CLR(fd,set) do { uint_t __i;\ 00291 for (__i = 0; __i < ((fd_set *)(set))->fd_count ; __i++) {\ 00292 if (((fd_set *)(set))->fd_array[__i] == (fd)) {\ 00293 while (__i < ((fd_set *)(set))->fd_count-1) {\ 00294 ((fd_set*)(set))->fd_array[__i] = ((fd_set*)(set))->fd_array[__i+1];\ 00295 __i++;\ 00296 }\ 00297 ((fd_set*)(set))->fd_count--;\ 00298 break;\ 00299 }\ 00300 }\ 00301 } while (0) 00302 00304 00305 #undef FD_SET 00306 #define FD_SET(fd, set) do { uint_t __i;\ 00307 for (__i = 0; __i < ((fd_set *)(set))->fd_count ; __i++) {\ 00308 if (((fd_set *)(set))->fd_array[__i] == (fd)) {\ 00309 break;\ 00310 }\ 00311 }\ 00312 if (__i == ((fd_set *)(set))->fd_count) {\ 00313 if (((fd_set *)(set))->fd_count < FD_SETSIZE) {\ 00314 ((fd_set *)(set))->fd_array[__i] = (fd);\ 00315 ((fd_set *)(set))->fd_count++;\ 00316 }\ 00317 }\ 00318 } while(0) 00319 00321 00322 #undef FD_ZERO 00323 #define FD_ZERO(set) (((fd_set*)(set))->fd_count=0) 00324 00326 00327 #undef FD_ISSET 00328 #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set)) 00329 00331 00332 extern "C" 00333 { 00334 SOCKET WINAPI accept(SOCKET, struct sockaddr*, int*); 00335 int WINAPI bind(SOCKET, const struct sockaddr*, int); 00336 int WINAPI connect(SOCKET, const struct sockaddr*, int); 00337 int WINAPI getaddrinfo( 00338 const char*, 00339 const char*, 00340 const struct addrinfo*, 00341 struct addrinfo**); 00342 hostent* WINAPI gethostbyaddr(const char*, int, int); 00343 hostent* WINAPI gethostbyname(const char*); 00344 int WINAPI gethostname(char*, int); 00345 int WINAPI getsockopt(SOCKET, int, int, char*, int*); 00346 int WINAPI setsockopt(SOCKET, int, int, const char*, int); 00347 WORD WINAPI htons(WORD); 00348 WORD WINAPI ntohs(WORD); 00349 int WINAPI listen(SOCKET, int); 00350 int WINAPI recv(SOCKET, char*, int, int); 00351 SOCKET WINAPI socket(int, int, int); 00352 int WINAPI select( 00353 int, 00354 fd_set*, 00355 fd_set*, 00356 fd_set*, 00357 const struct timeval*); 00358 int WINAPI send(SOCKET, const char*, int, int); 00359 int WINAPI WSACleanup(); 00360 int WINAPI WSAGetLastError(); 00361 int WINAPI WSAStartup(WORD, WSADATA*); 00362 int WINAPI __WSAFDIsSet(SOCKET, fd_set*); 00363 } 00364 00366 00367 #endif 00368 00370 00371 #endif
Conclusion
Grâce au fichier d'entête précédent, nous pouvons donc observer les différents prototypes (illisibles) des fonctions (incompréhensibles) de la bibliothèque (inutilisable) de Windows. Nous pouvons par ailleurs constater toute la finesse qu'a employé les concepteurs de cette librairie pour concevoir les identifiants des fonctions, types et variables, simples d'accès pour programmeur lambda et respectant toute la sémantique de leur utilité. En effet, si on prends comme exemple la fonction "getsockopt", on déduit naturellement qu'elle permet de guetter des chaussettes en option.
Sans prendre connaissance de ce fichier, un programmeur de type normal est incapable de faire quoi que ce soit de cette librairie. En le faisant (et après avoir pleuré un bon coup), il sait désormais quoi inclure dans son programme.
Il ne reste plus qu'à savoir à quoi ça sert.
S'il vous a enthousiasmé, votez pour lui sur sa page de vote ! Ou pas.