Download code

This is a discussion on Download code within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by maxorator 4 C:\Programs\Dev-Cpp\Templates\main6.cpp `main' must return `int' main must start with int, and return a int, the ...

  1. #16
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Quote Originally Posted by maxorator
    4 C:\Programs\Dev-Cpp\Templates\main6.cpp `main' must return `int'

    main must start with int, and return a int,
    the following is a example on how main should be declared.

    Code:
    int main()
    {
    
         return 0;
    }
    for some applications you may need

    INT WINAPI MAIN()

    or

    int WINAPI MAIN()


    either way it shoudl start with int and return int.

    that will get rid of that error.

    for your other error your not linking to something correctly
    your prolyl doing a consoel application when you should
    be picking a windows application on devc++.

  2. #17
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    The example there showed
    Code:
    #include <stdio.h>
    #include "winsock2.h"
    
    void main() {
      return;
    }

  3. #18
    Banned
    Join Date
    Jun 2005
    Posts
    594
    doesnt mean there right...

    main always returns and int.

    you dont have a a choice in the matter.

    i noticed alot of code sample on msdn,
    use void main(), but maybe its C related,
    i dont know all the querks of C, but
    for c++, since you are using a c++ compiler,
    main returns int. no if's and's or but's

  4. #19
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    And this is their "complete" code:
    Code:
    #include <stdio.h>
    #include "winsock2.h"
    
    void main() {
    
        // Initialize Winsock.
        WSADATA wsaData;
        int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
        if ( iResult != NO_ERROR )
            printf("Error at WSAStartup()\n");
    
        // Create a socket.
        SOCKET m_socket;
        m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
    
        if ( m_socket == INVALID_SOCKET ) {
            printf( "Error at socket(): %ld\n", WSAGetLastError() );
            WSACleanup();
            return;
        }
    
        // Connect to a server.
        sockaddr_in clientService;
    
        clientService.sin_family = AF_INET;
        clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
        clientService.sin_port = htons( 27015 );
    
        if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) {
            printf( "Failed to connect.\n" );
            WSACleanup();
            return;
        }
    
        // Send and receive data.
        int bytesSent;
        int bytesRecv = SOCKET_ERROR;
        char sendbuf[32] = "Client: Sending data.";
        char recvbuf[32] = "";
    
        bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );
        printf( "Bytes Sent: %ld\n", bytesSent );
    
        while( bytesRecv == SOCKET_ERROR ) {
            bytesRecv = recv( m_socket, recvbuf, 32, 0 );
            if ( bytesRecv == 0 || bytesRecv == WSAECONNRESET ) {
                printf( "Connection Closed.\n");
                break;
            }
            if (bytesRecv < 0)
                return;
            printf( "Bytes Recv: %ld\n", bytesRecv );
        }
    
        return;
    }

  5. #20
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    If all you want to do is download files clean and simple, the solution was already given in the third post.

    Code:
    URLDownloadToFile( NULL, "http://www.google.com/intl/en_us/images/logo.gif", "c:\\google_logo.jpg", 0, NULL );
    Check what headers and libs you need at the link given by Tonto. Make sure you check return values.

    Maybe socket programming is a bit over your head just now and all you need is this simplified functionality.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #21
    Banned
    Join Date
    Jun 2005
    Posts
    594
    changing it to int main(), and return 0;

    will not affect your program in anyway, quit
    acting like its life or death make the change and move on.

  7. #22
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by nvoigt
    If all you want to do is download files clean and simple, the solution was already given in the third post.

    Code:
    URLDownloadToFile( NULL, "http://www.google.com/intl/en_us/images/logo.gif", "c:\\google_logo.jpg", 0, NULL );
    Check what headers and libs you need at the link given by Tonto. Make sure you check return values.

    Maybe socket programming is a bit over your head just now and all you need is this simplified functionality.
    What header file do I need for that?

  8. #23
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Check what headers and libs you need at the link given by Tonto.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  9. #24
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Ok, at last I found something that really works fine: http://www.whyaskwhy.org/programming....winh.cpp.html

  10. #25
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I'm so glad you found a nice copy and paste example instead of reading the ample documentation we provided.

  11. #26
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I cant use the ample documentation you provided because I dont have urlmon.h file! This is the only thing that works without urlmon.h.

  12. #27
    Banned
    Join Date
    Jun 2005
    Posts
    594
    out of curiosity how do you know you dont have it?
    what compiler are you using?

  13. #28
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Dev-c++

  14. #29
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by maxorator
    I cant use the ample documentation you provided because I dont have urlmon.h file! This is the only thing that works without urlmon.h.
    Which documentation required that file? There were about 4 listed and I'm sure it wasnt all of them, nor can I find the right one.. wasnt MSDN was it?
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  15. #30
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    This thread is SOLVED!!! Someone's got problems understanding it

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Is this right?(about a class) (code to download) etc..
    By knave in forum C++ Programming
    Replies: 0
    Last Post: 07-07-2003, 07:53 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-15-2002, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21