Microsoft KB Archive/822334

= BUG: Cannot locate the procedure entry point FreeAddrInfoW when you run an application on Windows Server 2003 or on Windows XP =

Article ID: 822334

Article Last Modified on 4/19/2007

-

APPLIES TO

 Microsoft Visual C++ .NET 2003 Standard Edition Microsoft Visual C++ .NET 2002 Standard Edition, when used with:  Microsoft Windows Server 2003, Datacenter Edition (32-bit x86)

 Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)

 Microsoft Windows Server 2003, Standard Edition (32-bit x86)

 Microsoft Windows Server 2003, Web Edition</li></ul>

 Microsoft Windows XP Professional</li></ul>

 Microsoft Windows XP Home Edition</li></ul> </li></ul>

-

<div class="notice_section">

<div class="notice_section">

Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.

<div class="symptoms_section">

SYMPTOMS
When you run a Unicode-enabled application that uses the FreeAddrInfo Windows Sockets function, or that uses helper classes such as ATL::CSocketAddr on a computer that is running Microsoft Windows Server 2003 or Microsoft Windows XP, you may receive the following error message:

The procedure entry point FreeAddrInfoW could not be located in the dynamic link library WS2_32.dll.

<div class="cause_section">

CAUSE
The ws2_32.dll library does not export the FreeAddrInfoW symbol that you must have to use the Unicode version of the FreeAddrInfo function.

<div class="resolution_section">

RESOLUTION
To resolve this problem, follow these steps: <ol> 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

</li>  Add the following block of code to the copy of the Atlsocket.h file that you created in step 1. //Atlsocket.h //Start of Addition #define ADDRINFOT addrinfo #define GetAddrInfo getaddrinfo #define FreeAddrInfo freeaddrinfo //End of Addition namespace ATL </li> Start Microsoft Visual C++.</li> On the Tools menu, click Options. In the left pane of the Options dialog box, expand Projects, and then click VC++ Directories.
 * 1) pragma comment(lib, &quot;ws2_32.lib&quot;)
 * 2) pragma comment(lib, &quot;mswsock.lib&quot;)
 * 1) if _WIN32_WINNT < 0x0502
 * 1) endif

Note If you are using Visual C++ Express Edition, expand Projects and Solutions in the left pane of the Options dialog box, and then click VC++ Directories.</li> 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.</li> Rebuild you application</li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.

<div class="moreinformation_section">

Steps to reproduce the problem
<ol> Start Microsoft Visual Studio .NET 2003.</li> On the File menu, point to New, and then click Project.</li> Click Visual C++ Projects under Project Types. Then, click Win32 Console Project under Templates.</li> In the Name box, type Sample, and then click OK.</li> <li>In the Win32 Application Wizard dialog box, click to select the ATL and the Add Support for check boxes under Application Settings, and then click Finish.</li> <li> In the Sample.cpp file, replace the existing default code with the following code.
 * 1) include &quot;stdafx.h&quot;
 * 2) include <atlsocket.h>

void _tmain {   CSocketAddr aSocketAddr; } </li> <li>In Solution Explorer, right-click the project node, and then click Properties.</li> <li>In the project Property Pages dialog box, click General under Configuration Properties in the left pane. In the right pane, set the Character Set property to Use Unicode Character Set. Click OK.</li> <li>On the Build menu, click Build Solution to build the application. You may notice that no compilation errors or linking errors occur during the build process.</li> <li>On the Debug menu, click Start Without Debugging. You may notice that you receive the error message that is described in the &quot;Symptoms&quot; section.</li></ol>

In Windows Server 2003 and in Windows XP, new Windows Sockets functions are added to the Windows Socket API. GetAddrInfo and FreeAddrInfo are the two new Windows Sockets functions that are added for dealing with both Internet Protocol version 6 (IPv6) and Internet Protocol version 4 (IPv4) addresses. The Active Template Library (ATL) 7.1 CSocketAddr class uses these new Windows Socket functions to provide support for IPv6. Other ATL and Microsoft Foundation Classes (MFC) classes also use the CSocketAddr class to provide IPv6 support. For example, the CAsyncSocket class and the CSMTPConnection class use the CSocketAddr class.

Note The CAsyncSocket class is an MFC class. The CSMTPConnection class is an ATL class.

The problem that is described in the &quot;Symptoms&quot; section occurs in any Unicode-enabled application that uses the FreeAddrInfo Windows Socket function on a computer that is running Windows Server 2003 or Windows XP. Because the ATL CSocketAddr class uses the FreeAddrInfo function, the same problem also occurs in ATL 7.1. Any class in ATL 7.1 and MFC 7.1 that uses the CSocketAddr class to enable IPv6 support reflects this behavior. For example, the CAsyncSocket class and the CSMTPConnection class use the CSocketAddr class.

ATL server classes such as CAtlHttpClient and CSoapSocketClientT use the ZEvtSyncSocket class, and display the same error. This behavior occurs because the ZEvtSyncSocket internal class uses the CSocketAddr class in its implementation.

Note The CAtlHttpClient class provides HTTP client support. The CSoapSocketClientT class provides XML Web services client support.

<div class="references_section">