none
Winsock2 error: The procedure entry point XXXX cold not be located in (...) WS2_32.dll

    Question

  •  

    Hello,

    i am programming a cross-platform program with network capability to run under windowsXP (and later) and linux.
    I need functionality for inet_pton and inet_ntop.
    I found out that inet_pton and inet_ntop are both defined in <ws2tcpip.h>. So I thought great, if those commands are usable under windows and linux as well i do not need an ifdef.

    I can write a program which will get compiled and linked without problems.

    But as soon as I start my Program (that uses inet_pton or inet_ntop) i get a
    "The procedure entry point inet_ntop cold not be located in the dynamic link library WS2_32.dll"
    error message.

    I did not find anything useful on the net for this problem. Can anybody give me a direction how to fix this and why this happens? Btw: I also get a similar error if i use the InetNtop() method instead of inet_ntop found on msdn here

    Here an example program that produces the error:

     
    #include <iostream> 
    #include <winsock2.h> 
    #include <ws2tcpip.h> 
    #include <stdint.h> 
     
    using namespace std;  
    int main()  
    {  
     
            uint32_t bitmask =  55;  
            struct in_addr theAddr;  
            uint32_t inv_mask = -1;  
            char dst[16];  
            inet_pton(AF_INET, "ij2", &theAddr);  
            if (bitmask < 32) {  
                inv_maskinv_mask = inv_mask >> bitmask;  
                theAddr.s_addr = htonl(ntohl(theAddr.s_addr) | inv_mask);  
            }  
            if (inet_ntop(AF_INET, &theAddr, dst, sizeof(dst)) != NULL)  
                cout << "dummy";  
        return 0;  
     
          




    no additional preprocessor definitions used, library includes :  Ws2_32.lib  Iphlpapi.lib  [wsock32.lib]

    My System:
    WinXP Professional Version 2002, Service Pack 2;

    Microsoft Visual Studio 2008
    Version 9.0.21022.8 RTM
    Microsoft .NET Framework
    Version 3.5

    Installed Edition: VC Express

    Microsoft Visual C++ 2008   91909-152-0000052-60620
    Microsoft Visual C++ 2008

    Hotfix for Microsoft Visual C++ 2008 Express Edition - ENU (KB945282)   KB945282
    Hotfix for Microsoft Visual C++ 2008 Express Edition - ENU (KB946040)   KB946040

    Monday, February 09, 2009 10:45 AM

Answers

  • When you target old operating systems, it is important that you set the _WIN32_WINNT macro value correctly.  Use 0x501 for XP.  That will then produce a compile error, inet_ntop() is only available on Vista.  You could consider inet_ntoa().
    Hans Passant.
    • Marked as answer by Phelyks Tuesday, February 10, 2009 12:33 PM
    Monday, February 09, 2009 12:48 PM
    Moderator

All replies

  • When you target old operating systems, it is important that you set the _WIN32_WINNT macro value correctly.  Use 0x501 for XP.  That will then produce a compile error, inet_ntop() is only available on Vista.  You could consider inet_ntoa().
    Hans Passant.
    • Marked as answer by Phelyks Tuesday, February 10, 2009 12:33 PM
    Monday, February 09, 2009 12:48 PM
    Moderator
  • thank you for your response! You are right, if i define it, I get the described error.
    I was completely unaware of this!

    Just one more question, can I write my method using this or some other so that it will compile on multiple OS?
    So that I am able to identify if I compile under Vista/under an OS that has support for the method?
    I am thinking of something in the lines of

    int inet_pton_generic(int af, const char* src, void* dst)  
    {  
    #ifndef _WIN32  
        return inet_pton(af, src, dst);  
    #else  
    #if _WIN32_WINNT == 0x501  
        return 0;       //implementation here  
    #else if _WIN32_WINNT == 0x502  
        return inet_pton(af, src, dst);  
    #endif 
    }


    but in this case i would need to set this macro myself. Is there some macro that is set automatically?

    phelyks
    Tuesday, February 10, 2009 12:32 PM
  • #if (_WIN32_WINNT >= 0x600)
      // Okay to use inet_ntop()
    #endif

    Hans Passant.
    Tuesday, February 10, 2009 12:45 PM
    Moderator