关于“无法定位程序输入点getaddrinfo于动态链接库WS32_32.dll上”的问题

来源:互联网 发布:海关数据免费查询 编辑:程序博客网 时间:2024/05/01 09:52

文章来源:http://blog.csdn.net/k1988/article/details/4270580

今天收到一个bug,说我们的产品在windows 2000的操作环境下无法正常安装运行,安装后弹出“无法定位程序输入点getaddrinfo于动态链接库WS32_32.dll上”的错误。 简单地在网上搜了一下,发现多个讨论和解决方案。

方案一:http://hi.baidu.com/tjmd/blog/ITem/e35d0dd787b540dda144df98

   该问题一般出现在用VC编译的程序在XP和2003上可以正常运行,2000下则报此错误,解决方法比较简单,分两种情况,一种是对于VC6或者VC6升级到VC8的工程,修改编译选项中的_WIN32_WINNTWINVER0x0500,另一种是直接用VC8创建的工程,StdAfx.h里面已经有了这两个变量的定义,所以需要替换所有StdAfx.h文件里面_WIN32_WINNT和WINVER两个宏的变量,修改其值为0x0500,再编译即可解决!

方案二:http://topic.csdn.net/u/20080429/11/6167d25d-8b3c-4e21-8629-3b981f439c35.html

   使用静态连接
在编译开关里选择

方案三:http://topic.csdn.net/t/20060828/13/4980483.html   

应该说直接拷贝DLL是解决不了问题的。Top

6 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2006-08-28 13:24:07 得分 0

据我遇到的情况,是因为用到了getaddrinfo的的Unicode版本造成的(不管是直接还是间接),这个函数 (GetAddrInfoW),是Windows   XP   SP2才加上去的,低于XP   SP2的版本是无法用这个函数的,拷贝DLL也是不行的。需要改代码,然后再重新编译。Top

7 楼lixiaosan(小三)回复于 2006-08-28 13:26:23 得分50

http://support.microsoft.com/kb/822334/en-usTop

8 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2006-08-28 13:34:19 得分50

是不是用到了GetAddrInfo,FreeAddrInfo,CSocketAddr这些XP才支持的东东,需要你检查代码了。

方案四:http://support.microsoft.com/kb/822334/en-us

To resolve this problem, follow these steps:

  1. Copy the Atlsocket.h file to any directory that you want to use. This file is located in the following directory:
    Program Files/Microsoft Visual Studio .NET 2003/Vc7/atlmfc/include
  2. Add the following block of code to the copy of the Atlsocket.h file that you created in step 1.
    //Atlsocket.h#pragma comment(lib, "ws2_32.lib")#pragma comment(lib, "mswsock.lib")//Start of Addition#if _WIN32_WINNT < 0x0502  #define ADDRINFOT addrinfo  #define GetAddrInfo getaddrinfo  #define FreeAddrInfo freeaddrinfo#endif//End of Addition namespace ATL
  3. Start Microsoft Visual C++.
  4. On the Tools menu, click Options. In the left pane of the Options dialog box, expandProjects, and then click VC++ Directories.

    Note If you are using Visual C++ Express Edition, expand Projects and Solutions in the left pane of the Options dialog box, and then clickVC++ Directories.
  5. Under Show directories for, click Include files. Then, add the directory where the modified version of the Atlsocket.h file is located to the top of the list.
  6. Rebuild you application

但是我们代码没有使用 StdAfx.h并且已经是静态链接也不是一个ATL工程也就不能引用ATLBase.h,最后综合上面的解决方案和意见,改出了自己的版本。

将原有的#pragma comment(lib, "ws2_32.lib")改为了

#pragma comment(lib, "ws2_32.lib")

//Start of Addition
#if _WIN32_WINNT < 0x0502
  #define ADDRINFOT addrinfo
  #define GetAddrInfo getaddrinfo
  #define FreeAddrInfo freeaddrinfo
#endif
问题经测试已解决。