Answer» In trying to learn Winsock2 programming with Visual C++ 2005 Pro on Windows XP Pro SP3, I've run into a problem with an apparently corrupt MSWSOCK.dll.
Here's what I've tried so far:
// This is my second attempt at Winsock2 programming // A console PROGRAM built from the code given at // http://www.tenouk.com/Winsock/visualstudio2008ncnwinsock2.html // MDJ 2010/09/22
// Run on Windows XP Pro machine, version 2002, SP 2 // C++ from Visual Studio 2008 Pro Edition #include #include
// MDJ added the include below to further implement Winsock2
// Also added WS2_32.LIB and MSWSOCK.DLL under // Project|Windock2Test002 Properties| // Configuration Properties|Linker|Input| // Additional Dependencies
// Also set Project|Windock2Test002 Properties| // Configuration Properties|C/C++|Advanced|Compile As // to Compile as C Code (/TC).
// Got error message: // 1>LINK : fatal error LNK1104: cannot open file 'MSWSOCK.DLL' // Therefore: commented out the following include and // removed the MSWSOCK.DLL from the Additional // Dependencies list.
// [BUILD] succeded. // [Debug|Start Without Debugging] worked.
// Searched system to find MSWSOCK.DLL - 2/6/2010 at: // C:\WINDOWS\ServicePackFiles\i386\MSWSOCK.DLL. // Added complete path to Additional Dependencies list. // Uncommented the following include. Got: // 1>C:\WINDOWS\ServicePackFiles\i386\MSWSOCK.DLL : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2A8 // Tried earlier 8/4/2004 version at: // C:\WINDOWS\system32\MSWSOCK.DLL. // Got same result. Tried 2/6/2010 version at: // C:\WINDOWS\$NtServicePackUninstall$\MSWSOCK.DLL. // Got same result.
// Renamed MSWSOCK.DLL to MSWSOCKOld.DLL at: // C:\WINDOWS\ServicePackFiles\i386\MSWSOCK.DLL and at: // C:\WINDOWS\system32\MSWSOCK.DLL. // Downloaded new MSWSOCK.dll from: // http://www.dll-files.com/dllindex/dll-files.shtml?mswsock // to C:\downloadsHold\DLLs\mswsock then unzipped. // Version 11/18/2004 - copied to: // C:\WINDOWS\ServicePackFiles\i386\MSWSOCK.DLL and // C:\WINDOWS\system32\MSWSOCK.DLL. // Changed Additional Dependencies list to: // C:\WINDOWS\system32\MSWSOCK.DLL. Got: // 1>C:\WINDOWS\system32\MSWSOCK.DLL : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2A8
#include
int main() { WORD wVersionRequested; WSADATA wsaData; int wsaerr;
// Using MAKEWORD macro, Winsock version request 2.2 wVersionRequested = MAKEWORD(2, 2); wsaerr = WSAStartup(wVersionRequested, &wsaData);
if (wsaerr != 0) { /* Tell the USER that we could not find a usable */ /* WinSock DLL.*/ printf("The Winsock dll not FOUND!\n"); return 0; } else { printf("The Winsock dll found!\n"); printf("The STATUS: %s.\n", wsaData.szSystemStatus); }
/* 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("The dll do not support the Winsock version %u.%u!\n", LOBYTE(wsaData.wVersion),HIBYTE(wsaData.wVersion)); WSACleanup(); return 0; } else { printf("The dll supports the Winsock version %u.%u!\n", LOBYTE(wsaData.wVersion),HIBYTE(wsaData.wVersion)); printf("The highest version this dll can support: %u.%u\n", LOBYTE(wsaData.wHighVersion), HIBYTE(wsaData.wHighVersion)); }
/* More task... */ return 0; }
I've also searched the forum here and at codeguru.com and at bytes.com and at GeekPolice and at the SocialMSDNVisualC++Forum and found no help on this issue.
Any suggestions would be appreciated.
M. David Johnson
Banfa at bytes.com and S_M_A at codeguru.com both wrote that I should link on mswsock.lib instead of mswsock.dll.
I tried that and it worked.
M. David Johnson
|