| 1 | #ifndef WIN32_LEAN_AND_MEAN |
| 2 | #define WIN32_LEAN_AND_MEAN |
| 3 | #endif |
| 4 | #undef __CRT__NO_INLINE |
| 5 | #define __CRT__NO_INLINE |
| 6 | #include <winsock2.h> |
| 7 | #include <wspiapi.h> |
| 8 | |
| 9 | FARPROC WINAPI |
| 10 | WspiapiLoad (WORD wFunction) |
| 11 | { |
| 12 | static WINBOOL isinit = FALSE; |
| 13 | static WSPIAPI_FUNCTION rgtGlobal[] = WSPIAPI_FUNCTION_ARRAY; |
| 14 | static const int iNumGlobal = (sizeof(rgtGlobal) / sizeof(WSPIAPI_FUNCTION)); |
| 15 | HMODULE hlib = NULL; |
| 16 | WSPIAPI_FUNCTION rgtLocal[] = WSPIAPI_FUNCTION_ARRAY; |
| 17 | FARPROC fScratch = NULL; |
| 18 | int i = 0; |
| 19 | |
| 20 | if (isinit) |
| 21 | return rgtGlobal[wFunction].pfAddress; |
| 22 | |
| 23 | for (;;) |
| 24 | { |
| 25 | 	CHAR systemdir[MAX_PATH + 1], path[MAX_PATH + 8]; |
| 26 | |
| 27 | 	if (GetSystemDirectoryA (systemdir, MAX_PATH) == 0) |
| 28 | 	 break; |
| 29 | 	strcpy (path, systemdir); |
| 30 | 	strcat (path, "\\ws2_32"); |
| 31 | 	hlib = LoadLibraryA (path); |
| 32 | 	if(hlib != NULL) |
| 33 | 	 { |
| 34 | 	 fScratch = GetProcAddress (hlib, "getaddrinfo"); |
| 35 | 	 if (!fScratch) |
| 36 | 	 { |
| 37 | 		FreeLibrary (hlib); |
| 38 | 		hlib = NULL; |
| 39 | 	 } |
| 40 | 	 } |
| 41 | 	if (hlib != NULL) |
| 42 | 	 break; |
| 43 | 	strcpy (path, systemdir); |
| 44 | 	strcat (path, "\\wship6"); |
| 45 | 	hlib = LoadLibraryA (path); |
| 46 | 	if (hlib != NULL) |
| 47 | 	 { |
| 48 | 	 if ((fScratch = GetProcAddress (hlib, "getaddrinfo")) == NULL) |
| 49 | 	 { |
| 50 | 		FreeLibrary (hlib); |
| 51 | 		hlib = NULL; |
| 52 | 	 } |
| 53 | 	 } |
| 54 | 	break; |
| 55 | } |
| 56 | if (hlib != NULL) |
| 57 | { |
| 58 | 	for (i = 0; i < iNumGlobal; i++) |
| 59 | 	 { |
| 60 | 	 if ((rgtLocal[i].pfAddress = GetProcAddress (hlib, rgtLocal[i].pszName)) == NULL) |
| 61 | 	 { |
| 62 | 		FreeLibrary (hlib); |
| 63 | 		hlib = NULL; |
| 64 | 		break; |
| 65 | 	 } |
| 66 | 	 } |
| 67 | 	if (hlib != NULL) |
| 68 | 	 { |
| 69 | 	 for (i = 0; i < iNumGlobal; i++) |
| 70 | 	 rgtGlobal[i].pfAddress = rgtLocal[i].pfAddress; |
| 71 | 	 } |
| 72 | } |
| 73 | isinit = TRUE; |
| 74 | return rgtGlobal[wFunction].pfAddress; |
| 75 | } |