Discussion:
getaddrinfo() in MFC app
(too old to reply)
Roger
2005-08-08 21:01:05 UTC
Permalink
I can't get a VC6 MFC app to compile or link correctly on W2K with
getaddrinfo(). Here are the problems.

- Including Ws2tcpip.h and Wspiapi.h per docs produces "undeclared
identifier" errors for getaddrinfo() and freeaddrinfo(). If these includes
are located after include of stdafx.h there are multiple redefinitions which
I assume means the includes are rolled into my .pch anyway.

- Program will compile if I put the declarations for getaddrinfo() and
freeaddrinfo() directly in my code however these are unresolved in the link
stage. No version of the docs indicate what the library link requirements
are however July 2005 on-line MSDN entry says ws2_32.dll is needed. If I
link ws2_32.lib these functions are still unresolved.
Roger Hunen
2005-08-09 02:30:02 UTC
Permalink
According to the docs for these functions, getaddrinfo() and freeaddrinfo()
require Windows XP or Windows Server 2003.

Regards,
-Roger
--
E-mail: ***@xs4all.nl
Home: http://www.xs4all.nl/~rhunen
ADSL: http://adsl.hunen.net
Post by Roger
I can't get a VC6 MFC app to compile or link correctly on W2K with
getaddrinfo(). Here are the problems.
- Including Ws2tcpip.h and Wspiapi.h per docs produces "undeclared
identifier" errors for getaddrinfo() and freeaddrinfo(). If these includes
are located after include of stdafx.h there are multiple redefinitions which
I assume means the includes are rolled into my .pch anyway.
- Program will compile if I put the declarations for getaddrinfo() and
freeaddrinfo() directly in my code however these are unresolved in the link
stage. No version of the docs indicate what the library link requirements
are however July 2005 on-line MSDN entry says ws2_32.dll is needed. If I
link ws2_32.lib these functions are still unresolved.
Eugene Gershnik
2005-08-09 08:04:39 UTC
Permalink
Post by Roger Hunen
According to the docs for these functions, getaddrinfo() and
freeaddrinfo() require Windows XP or Windows Server 2003.
According to the docs

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/freeaddrinfo_2.asp

both functions are available on absolutely all Windows versions including 95
and NT4.
--
Eugene
http://www.gershnik.com
Arkady Frenkel
2005-08-09 10:00:21 UTC
Permalink
But not online msdn stand different things, and I remember that had problems
with it once but that work afterwards somehow :) , but how cares about W2K
now :)
Arkady
Post by Roger Hunen
Post by Roger Hunen
According to the docs for these functions, getaddrinfo() and
freeaddrinfo() require Windows XP or Windows Server 2003.
According to the docs
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/freeaddrinfo_2.asp
both functions are available on absolutely all Windows versions including
95 and NT4.
--
Eugene
http://www.gershnik.com
Roger Hunen
2005-08-09 20:43:59 UTC
Permalink
Post by Roger Hunen
Post by Roger Hunen
According to the docs for these functions, getaddrinfo() and
freeaddrinfo() require Windows XP or Windows Server 2003.
According to the docs
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/freeaddrinfo_2.asp
both functions are available on absolutely all Windows versions including 95 and NT4.
Hmm... I apparently need to update my platform SDK. Thanks!

Regards,
-Roger
--
E-mail: ***@xs4all.nl
Home: http://www.xs4all.nl/~rhunen
ADSL: http://adsl.hunen.net
Arkady Frenkel
2005-08-09 09:13:06 UTC
Permalink
That worked for me in W2K too ( obviously in XP ) but someone said that that
because I alread installed IPv6 stack ( and that time I really didn't
remember if W2K was with IPv6 or not , let's assume that it was with it ,
but for sure that worked for me ( more than 2 years I'm with XP only :) )
Arkady
Post by Roger Hunen
According to the docs for these functions, getaddrinfo() and
freeaddrinfo()
require Windows XP or Windows Server 2003.
Regards,
-Roger
--
Home: http://www.xs4all.nl/~rhunen
ADSL: http://adsl.hunen.net
Post by Roger
I can't get a VC6 MFC app to compile or link correctly on W2K with
getaddrinfo(). Here are the problems.
- Including Ws2tcpip.h and Wspiapi.h per docs produces "undeclared
identifier" errors for getaddrinfo() and freeaddrinfo(). If these includes
are located after include of stdafx.h there are multiple redefinitions which
I assume means the includes are rolled into my .pch anyway.
- Program will compile if I put the declarations for getaddrinfo() and
freeaddrinfo() directly in my code however these are unresolved in the link
stage. No version of the docs indicate what the library link
requirements
are however July 2005 on-line MSDN entry says ws2_32.dll is needed. If I
link ws2_32.lib these functions are still unresolved.
Arkady Frenkel
2005-08-09 09:57:30 UTC
Permalink
Additionally , be aware that MFC of VS6 don't support Winsock2 but 1 only
opposite to MFC of modern VSes ( 2003, 2005 ) so you need to change
standards headers to support Winsock2
Arkady
Post by Arkady Frenkel
That worked for me in W2K too ( obviously in XP ) but someone said that
that because I alread installed IPv6 stack ( and that time I really didn't
remember if W2K was with IPv6 or not , let's assume that it was with it ,
but for sure that worked for me ( more than 2 years I'm with XP only :) )
Arkady
Post by Roger Hunen
According to the docs for these functions, getaddrinfo() and
freeaddrinfo()
require Windows XP or Windows Server 2003.
Regards,
-Roger
--
Home: http://www.xs4all.nl/~rhunen
ADSL: http://adsl.hunen.net
Post by Roger
I can't get a VC6 MFC app to compile or link correctly on W2K with
getaddrinfo(). Here are the problems.
- Including Ws2tcpip.h and Wspiapi.h per docs produces "undeclared
identifier" errors for getaddrinfo() and freeaddrinfo(). If these includes
are located after include of stdafx.h there are multiple redefinitions which
I assume means the includes are rolled into my .pch anyway.
- Program will compile if I put the declarations for getaddrinfo() and
freeaddrinfo() directly in my code however these are unresolved in the link
stage. No version of the docs indicate what the library link requirements
are however July 2005 on-line MSDN entry says ws2_32.dll is needed. If I
link ws2_32.lib these functions are still unresolved.
Eugene Gershnik
2005-08-09 08:02:16 UTC
Permalink
Post by Roger
I can't get a VC6 MFC app to compile or link correctly on W2K with
getaddrinfo(). Here are the problems.
- Including Ws2tcpip.h and Wspiapi.h per docs produces "undeclared
identifier" errors for getaddrinfo() and freeaddrinfo(). If these
includes are located after include of stdafx.h there are multiple
redefinitions which I assume means the includes are rolled into my
.pch anyway.
See
http://www.gershnik.com/faq/compile.asp#redef
Post by Roger
- Program will compile if I put the declarations for getaddrinfo() and
freeaddrinfo() directly in my code however these are unresolved in
the link stage. No version of the docs indicate what the library
link requirements are however July 2005 on-line MSDN entry says
ws2_32.dll is needed. If I link ws2_32.lib these functions are still
unresolved.
Make sure you install and use a recent Platform SDK headers and libs. The
latest SDK can be found here
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
--
Eugene
http://www.gershnik.com
The Other Roger
2005-08-09 19:15:02 UTC
Permalink
Eugene,
The MS link you provided points to a May 2005 release of the Platform SDK
however info at that link also states that the last version that is compatible
with VC6 is the February 2003 release. I hadn't seen that statement before so I
downloaded the Feb 2003 release and have the exact same problems. Note that the
October 2001 MSDN which I believe is the last MSDN compatible with VC6 documents
getaddrinfo and freeaddrinfo so there should be a way of compiling and linking
these functions in VC6.

MS - I am posting from my registered MSDN alias so please respond to this
problem.

Roger
Post by Eugene Gershnik
Post by Roger
I can't get a VC6 MFC app to compile or link correctly on W2K with
getaddrinfo(). Here are the problems.
- Including Ws2tcpip.h and Wspiapi.h per docs produces "undeclared
identifier" errors for getaddrinfo() and freeaddrinfo(). If these
includes are located after include of stdafx.h there are multiple
redefinitions which I assume means the includes are rolled into my
.pch anyway.
See
http://www.gershnik.com/faq/compile.asp#redef
Post by Roger
- Program will compile if I put the declarations for getaddrinfo() and
freeaddrinfo() directly in my code however these are unresolved in
the link stage. No version of the docs indicate what the library
link requirements are however July 2005 on-line MSDN entry says
ws2_32.dll is needed. If I link ws2_32.lib these functions are still
unresolved.
Make sure you install and use a recent Platform SDK headers and libs. The
latest SDK can be found here
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
--
Eugene
http://www.gershnik.com
Eugene Gershnik
2005-08-09 20:02:27 UTC
Permalink
Post by The Other Roger
Eugene,
The MS link you provided points to a May 2005 release of the Platform
SDK however info at that link also states that the last version that
is compatible with VC6 is the February 2003 release.
Correct.
Post by The Other Roger
I hadn't seen
that statement before so I downloaded the Feb 2003 release
Correct. Did you set up its include and lib directories with VC?
Post by The Other Roger
and have
the exact same problems.
What *exact* problems?

I am using the same SDK and the output of

dumpbin /exports WS2_32.Lib

inlcudes
Post by The Other Roger
Note that the October 2001 MSDN which I
believe is the last MSDN compatible with VC6 documents getaddrinfo
and freeaddrinfo so there should be a way of compiling and linking
these functions in VC6.
If you set up your includes and libs correctly there shouldn't be any
problem.
--
Eugene
http://www.gershnik.com
Roger H. Levy
2005-08-09 22:06:17 UTC
Permalink
Eugene,
Here's what I did:
1. I installed the February 2003 Platform SDK.
2. Selected Start->Programs->Microsoft Platform SDK February 2003->Visual
Studio Registration->Register PSDK Directories with Visual Studio. Verified
in VS Tools->Options->Directories that this resulted in the PSDK include and
lib directories being shown first in their respective lists.
3. In VS6 Project->Settings->Link and the Input category I added "c:\program
files\microsoft sdk\lib\ws2_32.lib" to the Object/library modules list.
4. As you did I verified with dumpbin that the ws2_32.lib of step 3 exports
getaddrinfo and freeaddrinfo.
5. Found 3 other versions of ws2_32.lib on my system and renamed them all to
insure that somehow the wrong version was not being scanned.
6. However when I build the project getaddrinfo and freeaddrinfo are
unresolved externals. This is the case when I provide my own declarations
for the functions in my code.
7. If I include ws2tcpip.h and do not provide my own declarations then the
compiler issues errors that the functions are undeclared identifiers.
8. The project .plg file is a build log. I noticed that VS builds a
temporary batch file for the linker however this file is immediately and
automatically deleted. Perhaps if it were possible to examine this file I
could see what the problem with the linker is.

Roger
Post by Eugene Gershnik
Post by The Other Roger
Eugene,
The MS link you provided points to a May 2005 release of the Platform
SDK however info at that link also states that the last version that
is compatible with VC6 is the February 2003 release.
Correct.
Post by The Other Roger
I hadn't seen
that statement before so I downloaded the Feb 2003 release
Correct. Did you set up its include and lib directories with VC?
Post by The Other Roger
and have
the exact same problems.
What *exact* problems?
I am using the same SDK and the output of
dumpbin /exports WS2_32.Lib
inlcudes
Post by The Other Roger
Note that the October 2001 MSDN which I
believe is the last MSDN compatible with VC6 documents getaddrinfo
and freeaddrinfo so there should be a way of compiling and linking
these functions in VC6.
If you set up your includes and libs correctly there shouldn't be any
problem.
--
Eugene
http://www.gershnik.com
Eugene Gershnik
2005-08-09 23:58:22 UTC
Permalink
Post by The Other Roger
Eugene,
1. I installed the February 2003 Platform SDK.
2. Selected Start->Programs->Microsoft Platform SDK February
2003->Visual Studio Registration->Register PSDK Directories with
Visual Studio. Verified in VS Tools->Options->Directories that this
resulted in the PSDK include and lib directories being shown first in
their respective lists.
Ok
Post by The Other Roger
3. In VS6 Project->Settings->Link and the Input category I added
"c:\program files\microsoft sdk\lib\ws2_32.lib" to the Object/library
modules list.
The full path is not necessary. Just ws2_32.lib will do
Post by The Other Roger
4. As you did I verified with dumpbin that the ws2_32.lib of step 3
exports getaddrinfo and freeaddrinfo.
5. Found 3 other versions of ws2_32.lib on my system and renamed them
all to insure that somehow the wrong version was not being scanned.
Ok
Post by The Other Roger
6. However when I build the project getaddrinfo and freeaddrinfo are
unresolved externals. This is the case when I provide my own
declarations for the functions in my code.
Did you put __stdcall on your decalrations? Compare the missing name as
reported by linker with the one reported by dumpbin.
Post by The Other Roger
7. If I include ws2tcpip.h and do not provide my own declarations
then the compiler issues errors that the functions are undeclared
identifiers.
Verify that the function is in the header (getaddrinfo is on line 490 in my
header). If it most likely your ws2tcpip.h is not included because something
else (MFC?) defines _WS2TCPIP_H_.
Create an empty console application project an just include ws2tcpip.h.
Mention getaddrinfo in main(). If this does compile check your real project
for include file problems.
--
Eugene
http://www.gershnik.com
Roger H. Levy
2005-08-10 15:29:35 UTC
Permalink
Thanks but all suggestions have failed. I did get the application to
compile and link through a huge hack. I used extern "C" bracketing around
my function that uses getaddrinfo and freeaddrinfo and I also used extern
"C" to declare the function at the call location. I also provided my own
declarations of getaddrinfo and freeaddrinfo with _stdcall since the
declarations in ws2tcpip.h were not effective. The program started with
these hacks but immediately halted saying that getaddrinfo could not be
found in ws2_32.dll. I suppose it could be found in the ws2_32.dll from the
PDSK but I'm not interested in redistributing ws2_32.dll with my program.
It seems to me that MS has made a big mess out of this given that everything
was documented without any caveats in the October 2001 MSDN.

Roger
Post by Eugene Gershnik
Post by The Other Roger
Eugene,
1. I installed the February 2003 Platform SDK.
2. Selected Start->Programs->Microsoft Platform SDK February
2003->Visual Studio Registration->Register PSDK Directories with
Visual Studio. Verified in VS Tools->Options->Directories that this
resulted in the PSDK include and lib directories being shown first in
their respective lists.
Ok
Post by The Other Roger
3. In VS6 Project->Settings->Link and the Input category I added
"c:\program files\microsoft sdk\lib\ws2_32.lib" to the Object/library
modules list.
The full path is not necessary. Just ws2_32.lib will do
Post by The Other Roger
4. As you did I verified with dumpbin that the ws2_32.lib of step 3
exports getaddrinfo and freeaddrinfo.
5. Found 3 other versions of ws2_32.lib on my system and renamed them
all to insure that somehow the wrong version was not being scanned.
Ok
Post by The Other Roger
6. However when I build the project getaddrinfo and freeaddrinfo are
unresolved externals. This is the case when I provide my own
declarations for the functions in my code.
Did you put __stdcall on your decalrations? Compare the missing name as
reported by linker with the one reported by dumpbin.
Post by The Other Roger
7. If I include ws2tcpip.h and do not provide my own declarations
then the compiler issues errors that the functions are undeclared
identifiers.
Verify that the function is in the header (getaddrinfo is on line 490 in my
header). If it most likely your ws2tcpip.h is not included because something
else (MFC?) defines _WS2TCPIP_H_.
Create an empty console application project an just include ws2tcpip.h.
Mention getaddrinfo in main(). If this does compile check your real project
for include file problems.
Eugene Gershnik
2005-08-10 15:55:38 UTC
Permalink
Post by Roger H. Levy
Thanks but all suggestions have failed. I did get the application to
compile and link through a huge hack. I used extern "C" bracketing
around my function that uses getaddrinfo and freeaddrinfo and I also
used extern "C" to declare the function at the call location. I also
provided my own declarations of getaddrinfo and freeaddrinfo with
_stdcall since the declarations in ws2tcpip.h were not effective.
The program started with these hacks but immediately halted saying
that getaddrinfo could not be found in ws2_32.dll. I suppose it
could be found in the ws2_32.dll from the PDSK but I'm not interested
in redistributing ws2_32.dll with my program. It seems to me that MS
has made a big mess out of this given that everything was documented
without any caveats in the October 2001 MSDN.
Yes, when in doubt blame MS. There are enough things they deserve to be
bashed for but your problem is not one of them.
Your code is obviously broken as code using these functions compiles and
links fine with the same SDK you use. The fact that you made things to
compile and link with some extern "C" additions also indicates that your
code/project settings are broken. And no, you don't need to redistribute
ws2_32.dll from Platform SDK because there is no such thing. MSDN version
has nothing to do with it either.

If you think there is an error with SDK headers or libraries, create a small
application that demonstrates the problem (as I suggested in the previous
post) and post it here.
--
Eugene
http://www.gershnik.com
Roger H. Levy
2005-08-10 18:59:08 UTC
Permalink
Here is a small C program that demonstrates what I have been talking about
and is independent of the VS6 project structure -- this program can easily
be compiled and linked via "cl" on the command line:

#include "windows.h"
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};

main()
{
struct addrinfo *info;
struct addrinfo *walk;
char system[128];
unsigned char ip[4];
WSADATA wsaData;

int _stdcall getaddrinfo(const char FAR *nodename,
const char FAR *servname,
const struct addrinfo FAR *hints,
struct addrinfo FAR *FAR *res);
void _stdcall freeaddrinfo(struct addrinfo FAR *ai);

WSAStartup(MAKEWORD(2,0), &wsaData);
gethostname(system, sizeof system);
getaddrinfo(system, NULL, NULL, &info);

walk = info;
while(walk) {
memcpy(ip, &walk->ai_addr->sa_data[2], 4);
printf("%d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
walk = walk->ai_next;
}

freeaddrinfo(info);
return 0;
}

I can compile and run this C program on an XP system with the Platform SDK
for XP SP2 and it does the right thing which is to print the system's IP
addresses. For compactness this program omits a lot of error checking and
is not IPv6 compatible. Here are the problems.

1. I needed to provide my own declarations for getaddrinfo, freeaddrinfo,
and addrinfo because I can find no way to include ws2tcpip.h with windows.h
and not get duplicate definition errors. I'd be delighted if you could tell
me what includes can provide the definitions this program needs.
2. I want to include similar code in a VS6 project which means the code must
be compiled as C++. I can find no way to compile and link this code as C++.
3. In the end the code doesn't seem to be usable on anything other than XP
(maybe Win2003 server) because other Windows systems do not have the
function entry points in their ws2_32.dll. The MSDN documentation is
schizophrenic on this point with some versions saying these functions are
supported all the way back to Win9X and some versions saying otherwise (see
previous posts in this thread for examples of that confusion). It would be
nice if there was a redistributable ws2_32.dll to deal with this issue.

I use Microsoft development tools only when I have no choice so I am
probably not nearly as expert as you when it comes to MS development
esoterica. However I do not feel that I am unfairly blaming MS for making a
mess out of the use of these functions. If you can help me with the 3
issues above I'll cheerfully admit to being wrong.

Roger
Post by Eugene Gershnik
Post by Roger H. Levy
Thanks but all suggestions have failed. I did get the application to
compile and link through a huge hack. I used extern "C" bracketing
around my function that uses getaddrinfo and freeaddrinfo and I also
used extern "C" to declare the function at the call location. I also
provided my own declarations of getaddrinfo and freeaddrinfo with
_stdcall since the declarations in ws2tcpip.h were not effective.
The program started with these hacks but immediately halted saying
that getaddrinfo could not be found in ws2_32.dll. I suppose it
could be found in the ws2_32.dll from the PDSK but I'm not interested
in redistributing ws2_32.dll with my program. It seems to me that MS
has made a big mess out of this given that everything was documented
without any caveats in the October 2001 MSDN.
Yes, when in doubt blame MS. There are enough things they deserve to be
bashed for but your problem is not one of them.
Your code is obviously broken as code using these functions compiles and
links fine with the same SDK you use. The fact that you made things to
compile and link with some extern "C" additions also indicates that your
code/project settings are broken. And no, you don't need to redistribute
ws2_32.dll from Platform SDK because there is no such thing. MSDN version
has nothing to do with it either.
If you think there is an error with SDK headers or libraries, create a
small application that demonstrates the problem (as I suggested in the
previous post) and post it here.
--
Eugene
http://www.gershnik.com
Eugene Gershnik
2005-08-11 00:07:38 UTC
Permalink
Post by Roger H. Levy
Here is a small C program that demonstrates what I have been talking
about and is independent of the VS6 project structure -- this program
(Again you didn't post the code that exhibits the error.) Here is the
correct version that works

#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>

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

int main()
{
addrinfo *info;
addrinfo *walk;
char system[128];
unsigned char ip[4];
WSADATA wsaData;


WSAStartup(MAKEWORD(2,0), &wsaData);
gethostname(system, sizeof system);
getaddrinfo(system, NULL, NULL, &info);

walk = info;
while(walk) {
memcpy(ip, &walk->ai_addr->sa_data[2], 4);
printf("%d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
walk = walk->ai_next;
}

freeaddrinfo(info);
return 0;
}
Post by Roger H. Levy
1. I needed to provide my own declarations for getaddrinfo,
freeaddrinfo, and addrinfo because I can find no way to include
ws2tcpip.h with windows.h and not get duplicate definition errors. I'd be
delighted if you could tell me what includes can provide the
definitions this program needs.
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>

The fact that the includes must follow this order is the first reason to
bash MS.
Post by Roger H. Levy
2. I want to include similar code in a VS6 project which means the
code must be compiled as C++. I can find no way to compile and link
this code as C++.
Code above compiles as C++
Post by Roger H. Levy
3. In the end the code doesn't seem to be usable on anything other
than XP (maybe Win2003 server) because other Windows systems do not
have the function entry points in their ws2_32.dll. The MSDN
documentation is schizophrenic on this point with some versions
saying these functions are supported all the way back to Win9X and
some versions saying otherwise (see previous posts in this thread for
examples of that confusion).
Checking on my systems

Win98 SE (4.10.2222 A) - not present
WinME (4.90.3000) - not present
NT 4 SP6 (4.00.1381) - not present
Win2k Pro SP4 (5.00.2195) - not present
WinXP SP2 (5.1.2600) - present in ws2_32.dll
Win2k3 SP1 (5.2.3790) - present in ws2_32.dll
Vista (6.0.5112) - present in ws2_32.dll

The fact that the documentation is lying is the second reason to bash MS.
Post by Roger H. Levy
It would be nice if there was a
redistributable ws2_32.dll to deal with this issue.
There cannot be one as this dll is a part of the OS. On the systems where
the functions are missing you probably should fallback on gethostbyname.
--
Eugene
http://www.gershnik.com
hal korstead
2005-08-11 02:50:01 UTC
Permalink
Eugene,
I'll repeat the first sentence of this thread:
I can't get a VC6 MFC app to compile or link correctly on W2K with
getaddrinfo().
That is still true with your code. I tried the simplest possible
compilation after naming your code gai.c:
cl /c /I"\program files\microsoft sdk\include" gai.c
The include path points to the February 2003 PSDK which is the last version
claimed to be compatible with VC6. Your code threw a bunch of compilation
errors. Here are the first half dozen (I filtered out warnings):
gai.c(9) : error C2065: 'addrinfo' : undeclared identifier
gai.c(9) : error C2065: 'info' : undeclared identifier
gai.c(10) : error C2065: 'walk' : undeclared identifier
gai.c(11) : error C2143: syntax error : missing ';' before 'type'
gai.c(12) : error C2143: syntax error : missing ';' before 'type'
gai.c(13) : error C2275: 'WSADATA' : illegal use of this type as an expression
\program files\microsoft sdk\include\winsock2.h(423) : see declaration of
'WSADATA'

If this code compiles for you in an equivalent environment to the one I
specified then I can only assume that more is needed than a default
compilation command. I'm going to start a new thread on this topic tomorrow
under a registered MSDN alias for which my employer pays a lot of money.
Microsoft is supposed to be obligated to supply an answer in that case.
Unfortunately you seemed more interested in being critical as opposed to
being truly helpful. Maybe I'll have better luck with a new thread.

Roger
Post by Eugene Gershnik
Post by Roger H. Levy
Here is a small C program that demonstrates what I have been talking
about and is independent of the VS6 project structure -- this program
(Again you didn't post the code that exhibits the error.) Here is the
correct version that works
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib")
int main()
{
addrinfo *info;
addrinfo *walk;
char system[128];
unsigned char ip[4];
WSADATA wsaData;
WSAStartup(MAKEWORD(2,0), &wsaData);
gethostname(system, sizeof system);
getaddrinfo(system, NULL, NULL, &info);
walk = info;
while(walk) {
memcpy(ip, &walk->ai_addr->sa_data[2], 4);
printf("%d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
walk = walk->ai_next;
}
freeaddrinfo(info);
return 0;
}
Post by Roger H. Levy
1. I needed to provide my own declarations for getaddrinfo,
freeaddrinfo, and addrinfo because I can find no way to include
ws2tcpip.h with windows.h and not get duplicate definition errors. I'd be
delighted if you could tell me what includes can provide the
definitions this program needs.
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
The fact that the includes must follow this order is the first reason to
bash MS.
Post by Roger H. Levy
2. I want to include similar code in a VS6 project which means the
code must be compiled as C++. I can find no way to compile and link
this code as C++.
Code above compiles as C++
Post by Roger H. Levy
3. In the end the code doesn't seem to be usable on anything other
than XP (maybe Win2003 server) because other Windows systems do not
have the function entry points in their ws2_32.dll. The MSDN
documentation is schizophrenic on this point with some versions
saying these functions are supported all the way back to Win9X and
some versions saying otherwise (see previous posts in this thread for
examples of that confusion).
Checking on my systems
Win98 SE (4.10.2222 A) - not present
WinME (4.90.3000) - not present
NT 4 SP6 (4.00.1381) - not present
Win2k Pro SP4 (5.00.2195) - not present
WinXP SP2 (5.1.2600) - present in ws2_32.dll
Win2k3 SP1 (5.2.3790) - present in ws2_32.dll
Vista (6.0.5112) - present in ws2_32.dll
The fact that the documentation is lying is the second reason to bash MS.
Post by Roger H. Levy
It would be nice if there was a
redistributable ws2_32.dll to deal with this issue.
There cannot be one as this dll is a part of the OS. On the systems where
the functions are missing you probably should fallback on gethostbyname.
--
Eugene
http://www.gershnik.com
Eugene Gershnik
2005-08-11 07:56:54 UTC
Permalink
Post by The Other Roger
Eugene,
I can't get a VC6 MFC app to compile or link correctly on W2K with
getaddrinfo().
That is still true with your code. I tried the simplest possible
cl /c /I"\program files\microsoft sdk\include" gai.c
The include path points to the February 2003 PSDK
No it doesn't. Directories specified with /I are processed last after all
the compiler defaults. The switch is even called "*additional* include
directories" in the documentation. Most likely your headers are pulled from
the default VC location. You need to add a /X switch (or better yet compile
from IDE and set the directories there).
Post by The Other Roger
Unfortunately you seemed more interested in
being critical as opposed to being truly helpful.
Unfortunately you seem to be unable to help yourself or let others to help
you. Instead of concentrating on fixing the problem with your include and
lib paths you seem to be fixed on the idea that something is wrong with the
SDK.
I suggest you read

http://www.catb.org/~esr/faqs/smart-questions.html

before accusing anybody of being unhelpful.

Goog luck with your quest.
--
Eugene
http://www.gershnik.com
Alan J. McFarlane
2005-08-11 13:47:16 UTC
Permalink
Post by hal korstead
That is still true with your code. I tried the simplest possible
I haven't been following this thread, nor have I read it thoroughly. I
have one comment to make though at this point.

C != C++
Post by hal korstead
cl /c /I"\program files\microsoft sdk\include" gai.c
The include path points to the February 2003 PSDK which is the last
version claimed to be compatible with VC6. Your code threw a bunch
of compilation errors. Here are the first half dozen (I filtered out
gai.c(9) : error C2065: 'addrinfo' : undeclared identifier
gai.c(9) : error C2065: 'info' : undeclared identifier
gai.c(10) : error C2065: 'walk' : undeclared identifier
gai.c(11) : error C2143: syntax error : missing ';' before 'type'
gai.c(12) : error C2143: syntax error : missing ';' before 'type'
gai.c(13) : error C2275: 'WSADATA' : illegal use of this type as an
expression \program files\microsoft sdk\include\winsock2.h(423) : see
declaration of 'WSADATA'
If I compile Eugene's code as C++, it compiles fine. If I change it to
C, it fails with errors like those above.

And if I add "struct " before each of the declarations with "addrinfo"
it compiles fine with C too...


Also my first rule of Windows headers would likely help here too.
ALWAYS define WIN32_LEAN_AND_MEAN That stop windows.h from stupidly
including the obsolete winsock, and thus will not conflict with
winsock2.h even if it included later.


[...lots cut...]
--
Alan J. McFarlane
http://www.alanjmcf.me.uk/
Please follow-up in the newsgroup for the benefit of all.
Roger H. Levy
2005-08-11 15:16:44 UTC
Permalink
Thanks very much Alan. I didn't notice that in his apparent eagerness to be
critical of my code that Eugene had needlessly removed the "struct" keywords
thus making it invalid C. Also, to prevent others from possibly being
misled, it is not true as Eugene claims that default include directories are
scanned before ones explicitly specified by a /I option in the compile
command. The general wording in the documentation is ambiguous but the
example makes it clear that first the current directory is searched followed
by directories specified by /I followed by default directories, i.e. those
assigned to the INCLUDE environment variable Also, this behavior is easily
verified by copying a header file from a default to a local directory and
then putting a syntax error into the local file. If the /I option specifies
the local directory, the compiler will issue an error message.

Roger
Post by Alan J. McFarlane
Post by hal korstead
That is still true with your code. I tried the simplest possible
I haven't been following this thread, nor have I read it thoroughly. I
have one comment to make though at this point.
C != C++
Post by hal korstead
cl /c /I"\program files\microsoft sdk\include" gai.c
The include path points to the February 2003 PSDK which is the last
version claimed to be compatible with VC6. Your code threw a bunch
of compilation errors. Here are the first half dozen (I filtered out
gai.c(9) : error C2065: 'addrinfo' : undeclared identifier
gai.c(9) : error C2065: 'info' : undeclared identifier
gai.c(10) : error C2065: 'walk' : undeclared identifier
gai.c(11) : error C2143: syntax error : missing ';' before 'type'
gai.c(12) : error C2143: syntax error : missing ';' before 'type'
gai.c(13) : error C2275: 'WSADATA' : illegal use of this type as an
expression \program files\microsoft sdk\include\winsock2.h(423) : see
declaration of 'WSADATA'
If I compile Eugene's code as C++, it compiles fine. If I change it to C,
it fails with errors like those above.
And if I add "struct " before each of the declarations with "addrinfo" it
compiles fine with C too...
Also my first rule of Windows headers would likely help here too. ALWAYS
define WIN32_LEAN_AND_MEAN That stop windows.h from stupidly including
the obsolete winsock, and thus will not conflict with winsock2.h even if
it included later.
[...lots cut...]
--
Alan J. McFarlane
http://www.alanjmcf.me.uk/
Please follow-up in the newsgroup for the benefit of all.
Eugene Gershnik
2005-08-11 20:11:56 UTC
Permalink
Post by Roger H. Levy
Also, to
prevent others from possibly being misled, it is not true as Eugene
claims that default include directories are scanned before ones
explicitly specified by a /I option in the compile command. The
general wording in the documentation is ambiguous but the example
makes it clear that first the current directory is searched followed
by directories specified by /I followed by default directories,
To "prevent others from possibly being misled" here is the exact explanation

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_predir_the_.23.include_directive.asp

According to it you are wrong about the current directory being searched
first (for #include < >) and I was wrong about /I being last.
In any case include order is compiler specific and a fragile thing. Rather
than rely on documentation or experiments you should always make 100% sure
that you get the right file before assuming that the file is wrong.
--
Eugene
http://www.gershnik.com




i.e.
Post by Roger H. Levy
those assigned to the INCLUDE environment variable Also, this
behavior is easily verified by copying a header file from a default
to a local directory and then putting a syntax error into the local
file. If the /I option specifies the local directory, the compiler
will issue an error message.
Roger
Post by Alan J. McFarlane
Post by hal korstead
That is still true with your code. I tried the simplest possible
I haven't been following this thread, nor have I read it thoroughly.
I have one comment to make though at this point.
C != C++
Post by hal korstead
cl /c /I"\program files\microsoft sdk\include" gai.c
The include path points to the February 2003 PSDK which is the last
version claimed to be compatible with VC6. Your code threw a bunch
of compilation errors. Here are the first half dozen (I filtered
gai.c(9) : error C2065: 'addrinfo' : undeclared identifier
gai.c(9) : error C2065: 'info' : undeclared identifier
gai.c(10) : error C2065: 'walk' : undeclared identifier
gai.c(11) : error C2143: syntax error : missing ';' before 'type'
gai.c(12) : error C2143: syntax error : missing ';' before 'type'
gai.c(13) : error C2275: 'WSADATA' : illegal use of this type as an
see declaration of 'WSADATA'
If I compile Eugene's code as C++, it compiles fine. If I change it
to C, it fails with errors like those above.
And if I add "struct " before each of the declarations with
"addrinfo" it compiles fine with C too...
Also my first rule of Windows headers would likely help here too.
ALWAYS define WIN32_LEAN_AND_MEAN That stop windows.h from
stupidly including the obsolete winsock, and thus will not conflict
with winsock2.h even if it included later.
[...lots cut...]
--
Alan J. McFarlane
http://www.alanjmcf.me.uk/
Please follow-up in the newsgroup for the benefit of all.
Eugene Gershnik
2005-08-11 20:01:02 UTC
Permalink
Post by Alan J. McFarlane
If I compile Eugene's code as C++, it compiles fine. If I change it
to C, it fails with errors like those above.
And if I add "struct " before each of the declarations with "addrinfo"
it compiles fine with C too...
Yup. I overeagerly removed the "struct"s while cutting away the unnecessary
declarations from the original sample.
Post by Alan J. McFarlane
Also my first rule of Windows headers would likely help here too.
ALWAYS define WIN32_LEAN_AND_MEAN That stop windows.h from stupidly
including the obsolete winsock, and thus will not conflict with
winsock2.h even if it included later.
Unless you need something else hidden by WIN32_LEAN_AND_MEAN. I prefer
including winsock2 first in precompiled header.
In any case both methods were mentioned far in the beginning of the thread

http://www.gershnik.com/faq/compile.asp#redef
--
Eugene
http://www.gershnik.com
Arkady Frenkel
2005-08-14 13:59:12 UTC
Permalink
Eugene !
Additionally you can add to your faq that on run-time winsock2 called on NT
kernel Oses even if WSASetup called for winsock1 ( not like this on W9x )
Arkady
Post by Eugene Gershnik
Post by Alan J. McFarlane
If I compile Eugene's code as C++, it compiles fine. If I change it
to C, it fails with errors like those above.
And if I add "struct " before each of the declarations with "addrinfo"
it compiles fine with C too...
Yup. I overeagerly removed the "struct"s while cutting away the
unnecessary declarations from the original sample.
Post by Alan J. McFarlane
Also my first rule of Windows headers would likely help here too.
ALWAYS define WIN32_LEAN_AND_MEAN That stop windows.h from stupidly
including the obsolete winsock, and thus will not conflict with
winsock2.h even if it included later.
Unless you need something else hidden by WIN32_LEAN_AND_MEAN. I prefer
including winsock2 first in precompiled header.
In any case both methods were mentioned far in the beginning of the thread
http://www.gershnik.com/faq/compile.asp#redef
--
Eugene
http://www.gershnik.com
Loading...