Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Winsock2 console program failure


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 rnw159   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 May 2011 - 07:39 AM

My problem is that the console window jumps to system("pause") and skips any other commands or couts. If 2 system("pause") are present then the window closes after a key is pressed for the first system pause and then reopens for the seconds pause. The program continues to have a presence in the background, however, it is not visible unless there is a system("pause"). cin.get() and cin >> do not have the same effect that system("pause") has, and the window continues to remain invisible when they are called. I have narrowed it down to only happening if the program is compiled with #include <WinSock2.h>. The unique part is that even if I recompile without that header, the problem still stays for the entire project. I can only replicate the problem by creating new console projects. Once the project has been compiled with winsock2, the problem remains no matter what is written in the program.

I'm still experimenting so any new information will be posted.

Quote:

Original post by rnw159Screw game maker.

There's your sig quote for the forums :D[/quote]

Sponsor:

#2 Antheus   Members   -  Reputation: 2397

Like
1Likes
Like

Posted 02 May 2011 - 08:12 AM

It's a riveting story, so keep us posted. I'm curious how it turns out.

#3 rnw159   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 May 2011 - 08:18 AM

It's a riveting story, so keep us posted. I'm curious how it turns out.


Um thanks. Do you have any suggestions on how to fix the problem?

Quote:

Original post by rnw159Screw game maker.

There's your sig quote for the forums :D[/quote]

#4 Antheus   Members   -  Reputation: 2397

Like
0Likes
Like

Posted 02 May 2011 - 08:59 AM

Um thanks. Do you have any suggestions on how to fix the problem?


What problem?

There is no source code, no problem statement, no question...

Including wrong headers can cause problems. Not using API properly can cause problems. Bugs can cause problems. But there is nothing to go on here.

#5 rnw159   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 May 2011 - 09:13 AM


Um thanks. Do you have any suggestions on how to fix the problem?


What problem?

There is no source code, no problem statement, no question...

Including wrong headers can cause problems. Not using API properly can cause problems. Bugs can cause problems. But there is nothing to go on here.


Sorry, the reason there is no source code is because the source code is literaly this:
#include <cstdlib>
#include <iostream>


using namespace std;

int main(int argc, char *argv[])
{
    cout << "hi \n";
    system("PAUSE");
    return EXIT_SUCCESS;
}

The problem is that this won't show the words "hi". They used to show the words, but then I compiled the program with winsock2. Even though winsock2 is no longer there. The problem still persists.

Quote:

Original post by rnw159Screw game maker.

There's your sig quote for the forums :D[/quote]

#6 rnw159   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 May 2011 - 09:21 AM

The problem, it seems, has nothing to do with my code. When I compile with a header, it causes a bug. When I recompile without the header, the bug remains and doesn't go away. The header, winsock2, is causing a permanent change to my project and my compiler. Once I compile I can't ctrl-z and undo my change, the problem stays there for every future compile.

Quote:

Original post by rnw159Screw game maker.

There's your sig quote for the forums :D[/quote]

#7 Evil Steve   Members   -  Reputation: 1987

Like
0Likes
Like

Posted 02 May 2011 - 09:37 AM

And what compiler are you using?

Steve Macpherson
Systems Programmer

Rockstar North


#8 rnw159   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 May 2011 - 09:39 AM

And what compiler are you using?


First I was using vc++. The program I showed earlier was made using dev to see if changing compilers would fix the problem.

Quote:

Original post by rnw159Screw game maker.

There's your sig quote for the forums :D[/quote]

#9 Evil Steve   Members   -  Reputation: 1987

Like
0Likes
Like

Posted 02 May 2011 - 10:46 AM

It sounds like you've modified your project to be a Win32 application rather than a console application, in which case it's not created with a console window by default, but will open one when you call system() (Since it invokes the command interpreter).

However, using Winsock has nothing to do with toggling between Win32 / Console applications, and as far as I know, including winsock2.h won't affect the application type (I've used it in console apps countless times without issue).

What version of Visual Studio are you using, and where did winsock2.h come from - was it with the compiler, or did you download e.g. the platform SDK seperately?

Steve Macpherson
Systems Programmer

Rockstar North


#10 hplus0603   Moderators   -  Reputation: 5725

Like
0Likes
Like

Posted 02 May 2011 - 05:08 PM

#include <cstdlib>
#include <iostream>


using namespace std;

int main(int argc, char *argv[])
{
    cout << "hi \n";
    system("PAUSE");
    return EXIT_SUCCESS;
}

The problem is that this won't show the words "hi". They used to show the words, but then I compiled the program with winsock2. Even though winsock2 is no longer there. The problem still persists.


It's probably the case that your cout stream is not being flushed. Try printing to cerr instead, and try using std::endl instead of embedding a "\n" character -- Windows end line may not be \n alone.

Another option is that you're building as a "win32 application" rather than a "console application" -- check your linker settings.

Finally, console applications have to be started from the console/command line, rather than from within the debugger or the Explorer. Else they won't have the proper interactive TTY setup. (This is an oversimplification -- but for now, do it that way or you'll go crazy!)


This has nothing to do with networking, btw.
enum Bool { True, False, FileNotFound };

#11 rnw159   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 May 2011 - 07:23 PM


#include <cstdlib>
#include <iostream>


using namespace std;

int main(int argc, char *argv[])
{
    cout << "hi \n";
    system("PAUSE");
    return EXIT_SUCCESS;
}

The problem is that this won't show the words "hi". They used to show the words, but then I compiled the program with winsock2. Even though winsock2 is no longer there. The problem still persists.


It's probably the case that your cout stream is not being flushed. Try printing to cerr instead, and try using std::endl instead of embedding a "\n" character -- Windows end line may not be \n alone.

Another option is that you're building as a "win32 application" rather than a "console application" -- check your linker settings.

Finally, console applications have to be started from the console/command line, rather than from within the debugger or the Explorer. Else they won't have the proper interactive TTY setup. (This is an oversimplification -- but for now, do it that way or you'll go crazy!)


This has nothing to do with networking, btw.


Thanks, I will try that. I know the only correlation between this and networking in winsock2, but I thought this might be a problem that you had experienced before because people answering on this forum have probably used that library for a while.

Quote:

Original post by rnw159Screw game maker.

There's your sig quote for the forums :D[/quote]

#12 rnw159   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 May 2011 - 07:36 PM

Alright I tried all of your suggestions and non of them had any effect. The program always works fine until winsock2 is linked. Then, even when it is taken out, the problem persists.
*edit*
Alright, I just found out that my compiler is compiling it with:
g++.exe -D__DEBUG__ maindawdaw.o -o "Project2.exe" -L"C:/Dev-Cpp/lib" -L"C:/SDL-1.2.14/lib" ../../lib/libws2_32.a -g3 -mwindows
The obvious problem here is the -mwindows. How can I get it to compile without -mwindows?
*edit*
Manually changing the settings to console don't work. On compile the settings revert back to -mwindows.

Quote:

Original post by rnw159Screw game maker.

There's your sig quote for the forums :D[/quote]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS