I am posting two threads because I have two different problems, but both have the same background information.

Common Background Information:

I am trying to rebuild code for a working, commercially sold application with only partial build instructions. The previous maintainer of the code (a mixture of C and C++) is no longer with the company, but when he built the code he used MSVC++, and though I am not certain of the version he was using, I think it was either 4.0 or 6.0. I have only a little experience building with this environment (I am otherwise a seasoned developer) so I need help getting past a couple of issues that I have encountered. Computers (and backups of those computers) previously used for running this build are now completely unavailable.

I have set up the build on my system using MSVC++ 6.0. The source repository contained a workspace (.dsw) file that I am using for all of the projects. I do not have specific instructions for this product on how to adjust the references to libraries, includes, etc. for a particular machine, but I am using instructions for this from a similar (in terms of languages and tools used) product that was written around the same time. I have gotten 43 of 53 classes (projects) to build, but am getting primarily two errors with the remaining 10 clases (projects).

Because I know this code base was building properly (for someone else who is no longer available on a machine that is no longer available), I would strongly prefer adjustments to the build environment over code modification to get it to work, so please focus your assistance/suggestions in this area.

Thanks !

Problem #2: Getting Winsock.h instead of Winsock2.h

Here is part of the output I am receiving when I build:

Compiling...
srvsys.c
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(701) : error C2065: 'WSANETWORKEVENTS' : undeclared identifier
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(701) : error C2146: syntax error : missing ';' before identifier 'netevents'
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(701) : error C2065: 'netevents' : undeclared identifier
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(702) : error C2275: 'DWORD' : illegal use of this type as an expression
C:\PROGRAM FILES\MICROSOFT SDK\INCLUDE\windef.h(141) : see declaration of 'DWORD'
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(702) : error C2146: syntax error : missing ';' before identifier 'wait_value'
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(702) : error C2065: 'wait_value' : undeclared identifier
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(702) : error C2065: 'wait_index' : undeclared identifier
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(703) : error C2275: 'HANDLE' : illegal use of this type as an expression
C:\PROGRAM FILES\MICROSOFT SDK\INCLUDE\winnt.h(342) : see declaration of 'HANDLE'
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(703) : error C2146: syntax error : missing ';' before identifier 'hSocketEvent'
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(703) : error C2065: 'hSocketEvent' : undeclared identifier
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(704) : error C2275: 'SOCKET' : illegal use of this type as an expression
C:\PROGRAM FILES\MICROSOFT SDK\INCLUDE\winsock.h(40) : see declaration of 'SOCKET'
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(704) : error C2146: syntax error : missing ';' before identifier 'hIpcSocket'
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(704) : error C2065: 'hIpcSocket' : undeclared identifier
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(705) : error C2143: syntax error : missing ';' before 'type'
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(716) : warning C4013: 'WSACreateEvent' undefined; assuming extern returning int
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(716) : error C2065: 'WSA_INVALID_EVENT' : undeclared identifier
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(722) : warning C4013: 'WSAEventSelect' undefined; assuming extern returning int
D:\DEVELOP\Source\FAXFX\FAXFX\CCODE\FXAPI\SRVAPI\srvsys.c(730) : warning C4022: 'WaitForSingleObject' : pointer mismatch for actual parameter 1

Here are lines 701 through 730 of srvsys.c:

WSANETWORKEVENTS netevents;
	DWORD wait_value, wait_index;
	HANDLE hSocketEvent;
	SOCKET hIpcSocket;
	struct FXDEV_DS_MSG msg;

	sprintf( tcaller, "fxcipc(%6d)", GetCurrentThreadId( ) );
	trace_add_caller( 0, tcaller );

	trace( 7, "Start IPCThreadProc.\n");
	
	del_shut( );

	hIpcSocket = ( SOCKET ) SocketHandle;

	if ( ( hSocketEvent = WSACreateEvent( ) ) == WSA_INVALID_EVENT )
	{
		trace( 3, "Error: Unable to create monitor event [%d].\n", WSAGetLastError( ) );
		ExitProcess( 0 );
	}

	if ( WSAEventSelect( hIpcSocket, hSocketEvent, FD_READ | FD_CLOSE ) == SOCKET_ERROR )
	{
		trace( 3, "Error: Unable to set monitor event [%d].\n", WSAGetLastError( ) );
		ExitProcess( 0 );
	}

	while ( 1 )
	{	trace( 7, "Run IPCThreadProc.\n");
		wait_value = WaitForSingleObject( hSocketEvent, INFINITE );

The WSA stuff is only in Winsock2.h, but for some reason I am getting Winsock.h. I know this for two reasons: 1) the error messages (see above) indicate it, and 2) when I right click on SOCKET (in line 704 or in line 714) and choose "Go to Definition of SOCKET" it takes me to Winsock.H (not Winsock2.h).

So the question is, "How am I getting Winsock.h when I know the code is designed and was previously built using Winsock2.h?"

Any thoughts or suggestions from an experienced MSVC++ user would be greatly appreciated.

I seem to recall having similar issues at my previous job, I had some software to maintain in VC6 which threw up several errors when I first tried to compile the source, despite having paths set up to all of the relevant external libraries and includes...

winsock.h and winsock2.h were a couple of the headers which were conflicting...Amongst many others

All I did to solve the problem was alter the order of the includes and libraries and the conflicts ceased to be an issue. The sources I had compiled and built with no issues from then onwards!

To get rid of the winsock problem I found that the platform sdk had to be included before the standard VC98 includes.
I also had to move things like Zlib, Freetype and dxsdk above the VC98 includes to get rid of some of the other conflicts I was having!

To alter the include/library order in VC6:
Go to 'Tools->Options' and select the 'directories' tab.
In the 'show directories for' drop-down select 'include files' and ensure that the platform SDK include directory is above the VC98 includes. (select the entry for the platform SDK and move it up or down the list with the arrows in the dialog)

Similarly, select 'library files' from the 'show directories for' dropdown and ensure that the platform sdk lib folder is above the VC98 libs.

Note: if you don't have paths set up to the platform SDK lib/include directories, then you'll need to select a blank item at the bottom of each of the lists and enter the path to the relevant folder before moving it up to the top of the list.

The include order is usually the most crucial thing to change. Having the platform SDK library listed above the other libs might not be as important but it may help!

Alternatively, if that doesn't work here's a link to something I found that might help, but it looks like it would involve minor edits to your code:
http://www.digitalmars.com/d/archives/c++/idde/326.htm

Hopefully altering the include order will fix your problems, but do let me know how you get on!
Jas.

I received some suggestions that WIN32_LEAN_AND_MEAN should probably be set so that windows.h doesn't include winsock.h. I gave it a try even though my instincts told me that this would not be the root problem, since the workspace contains preprocessor definitions on every project, so if this is required it would already be there. Adding WIN32_LEAN_AND_MEAN to the preprocessor definitions of a couple of project caused a whole bunch of new errors and did not get rid of the old ones.

In response to suggestions that I have received regarding changing the order of include and library directory searches... I have tried several different orders with no noticeable impact. The order I have right now is Microsoft SDK first, third party includes and libraries second, and VC98 includes and libraries last. This seems the safest, but again no order seems to work (trying every single permutation would take quite a while.)

Lastly, and most importantly, it has come to my attention that the product that I am building is sold only for Server 2000 and Server 2003 and that the previous building of this code base was running on a Server 2003 system. Since I have been trying my builds on an XP machine, I am leaning towards setting up a virtual machine running Server 2003 in which to compile to see if this helps. However, since that will take a while to set up, I was hoping someone out there might have thoughts about whether or not this is likely to help.

Damn, I was certain that the include order was the problem...

hmmm......Which version of the platform SDK are you using?

If it is newer than the February 2003 version of the platform SDK then that could also be part of your woes....The Feb 2003 SDK was the last version to fully support VC6...Subsequent versions of the SDK do not work with VC6 and cause all kinds conflicts, compiler/linker errors and problems.

Took me a lot of googling to find out that nugget of info back in the day, I'd originally installed one of the 2005 PSDK's and ended up with more errors than when I started out. But installing the Feb 2003 SDK and then altering the include order (as previously described) fixed all of the problems I had.

As long as you at least have the same versions of the SDK (and the other libraries) that were used in the original build and your include order is correct, then I can't see any other obvious things that would cause these problems!

As you've mentioned in your other post, it could be that the previous version of your companies software was compiled on a different version of windows...Not sure if that would make that much of a difference though. The output from the VC6 compiler should be pretty much the same across the different versions of windows as it uses the same libraries and sources/includes to build the final executable.

Jas.

One thing I've just noted from reading your OP; you said that the original software could have been built using anything from VC4 to VC6 and that you were using a .dsw from your source repository.

By chance, did you try opening the .dsw with something like notepad to see what version of VC the .dsw was originally created with?

if it was created with VC6 you'll see the following in the top line:
"Microsoft Developer Studio Workspace File, Format Version 6.00"

If it was originally done for VC4 or VC5, then using VC6 could be the problem as several definitions, headers and libs would have changed between each of the VS versions...which could possibly account for some of the problems you're having!

Beside my suggestions in previous posts, the compiler version is the only other major factor that I can think of. Other than that I'm pretty much out of ideas!

J.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.