By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Corrupt MSWSOCK.dll

P: 6
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:

Expand|Select|Wrap|Line Numbers
  1. // This is my second attempt at Winsock2 programming
  2. // A console program built from the code given at 
  3. // http://www.tenouk.com/Winsock/visualstudio2008ncnwinsock2.html
  4. // MDJ 2010/09/22
  5.  
  6. // Run on Windows XP Pro machine, version 2002, SP 2
  7. // C++ from Visual Studio 2008 Pro Edition
  8. #include <stdio.h>
  9. #include <winsock2.h>
  10.  
  11. // MDJ added the include below to further implement Winsock2
  12.  
  13. // Also added WS2_32.LIB and MSWSOCK.DLL under
  14. // Project|Windock2Test002 Properties|
  15. // Configuration Properties|Linker|Input|
  16. // Additional Dependencies
  17.  
  18. // Also set Project|Windock2Test002 Properties|
  19. // Configuration Properties|C/C++|Advanced|Compile As
  20. // to Compile as C Code (/TC).
  21.  
  22. // Got error message:
  23. // 1>LINK : fatal error LNK1104: cannot open file 'MSWSOCK.DLL'
  24. // Therefore: commented out the following include and 
  25. // removed the MSWSOCK.DLL from the Additional
  26. // Dependencies list.
  27.  
  28. // [Build] succeded.
  29. // [Debug|Start Without Debugging] worked.
  30.  
  31. // Searched system to find MSWSOCK.DLL - 2/6/2010 at:
  32. // C:\WINDOWS\ServicePackFiles\i386\MSWSOCK.DLL.
  33. // Added complete path to Additional Dependencies list.
  34. // Uncommented the following include. Got:
  35. // 1>C:\WINDOWS\ServicePackFiles\i386\MSWSOCK.DLL : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2A8
  36. // Tried earlier 8/4/2004 version at:
  37. // C:\WINDOWS\system32\MSWSOCK.DLL.
  38. // Got same result. Tried 2/6/2010 version at:
  39. // C:\WINDOWS\$NtServicePackUninstall$\MSWSOCK.DLL.
  40. // Got same result.
  41.  
  42. // Renamed MSWSOCK.DLL to MSWSOCKOld.DLL at:
  43. // C:\WINDOWS\ServicePackFiles\i386\MSWSOCK.DLL and at:
  44. // C:\WINDOWS\system32\MSWSOCK.DLL.
  45. // Downloaded new MSWSOCK.dll from:
  46. // http://www.dll-files.com/dllindex/dll-files.shtml?mswsock
  47. // to C:\downloadsHold\DLLs\mswsock then unzipped.
  48. // Version 11/18/2004 - copied to:
  49. // C:\WINDOWS\ServicePackFiles\i386\MSWSOCK.DLL and
  50. // C:\WINDOWS\system32\MSWSOCK.DLL.
  51. // Changed Additional Dependencies list to:
  52. // C:\WINDOWS\system32\MSWSOCK.DLL. Got:
  53. // 1>C:\WINDOWS\system32\MSWSOCK.DLL : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2A8
  54.  
  55.  
  56. #include <mswsock.h>
  57.  
  58. int main()
  59. {
  60.     WORD wVersionRequested;
  61.     WSADATA wsaData;
  62.     int wsaerr;
  63.  
  64.     // Using MAKEWORD macro, Winsock version request 2.2
  65.       wVersionRequested = MAKEWORD(2, 2);
  66.       wsaerr = WSAStartup(wVersionRequested, &wsaData);
  67.  
  68.       if (wsaerr != 0)
  69.       {
  70.             /* Tell the user that we could not find a usable */
  71.             /* WinSock DLL.*/
  72.             printf("The Winsock dll not found!\n");
  73.             return 0;
  74.       }
  75.       else
  76.       {
  77.             printf("The Winsock dll found!\n");
  78.             printf("The status: %s.\n", wsaData.szSystemStatus);
  79.       }
  80.  
  81.       /* Confirm that the WinSock DLL supports 2.2.        */
  82.       /* Note that if the DLL supports versions greater    */
  83.       /* than 2.2 in addition to 2.2, it will still return */
  84.       /* 2.2 in wVersion since that is the version we      */
  85.       /* requested.                                        */
  86.  
  87.       if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2 )
  88.       {
  89.             /* Tell the user that we could not find a usable */
  90.             /* WinSock DLL.*/
  91.             printf("The dll do not support the Winsock version %u.%u!\n", LOBYTE(wsaData.wVersion),HIBYTE(wsaData.wVersion));
  92.             WSACleanup();
  93.             return 0;
  94.       }
  95.       else
  96.       {
  97.             printf("The dll supports the Winsock version %u.%u!\n", LOBYTE(wsaData.wVersion),HIBYTE(wsaData.wVersion));
  98.             printf("The highest version this dll can support: %u.%u\n", LOBYTE(wsaData.wHighVersion), HIBYTE(wsaData.wHighVersion));
  99.       }
  100.  
  101.     /* More task... */
  102.       return 0;
  103. }
  104.  
I've also searched the forum here and at GeekPolice and at the SocialMSDNVisualC++Forum and found no help on this issue.

Any suggestions would be appreciated.

M. David Johnson
Sep 22 '10 #1

✓ answered by Banfa

So a couple of things,
  • You never link against a DLL you always link against a lib. This is the reason for your "LNK1107: invalid or corrupt file" error. The linker was expecting to find the format of a lib or object file but you supplied a DLL what has quite a different format.
  • If the build succeeded without out it what are you still trying to add it? (Of course you may not have finished your program yet and may be adding functions from it)
  • If you really need to use Mswsock.dll then link against Mswsock.lib.
  • I would get rid of the 3rd party supplied Mswsock.dll and go back to using the originals since it is the best way of ensuring the versions all match up.

Share this Question
Share on Google+
3 Replies


P: 6
Apparently, even though I type in the "[/code]" line properly, the system insists on displaying it as "{/CODE]" instead, i.e. using a leading brace instead of the leading bracket.

The mechanism also doesn't appear to do anything.

What am I doing wrong?

M. David Johnson
Sep 22 '10 #2

Banfa
Expert Mod 5K+
P: 8,916
So a couple of things,
  • You never link against a DLL you always link against a lib. This is the reason for your "LNK1107: invalid or corrupt file" error. The linker was expecting to find the format of a lib or object file but you supplied a DLL what has quite a different format.
  • If the build succeeded without out it what are you still trying to add it? (Of course you may not have finished your program yet and may be adding functions from it)
  • If you really need to use Mswsock.dll then link against Mswsock.lib.
  • I would get rid of the 3rd party supplied Mswsock.dll and go back to using the originals since it is the best way of ensuring the versions all match up.
Sep 22 '10 #3

P: 6
Thanks -

I linked on MSWSOCK.Lib instead of MSWSOCK.dll.

[Build] succeded.
[Debug|Start Without Debugging] worked.

This is indeed a very minimal shell to which I intend to add many other features as I learn more and more about Winsock2 programming. That's why I added MSWSOCK even though the program compiles and works without it.

Thanks again.

M. David Johnson
Sep 23 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.