Thread: InternetConnect fails

  1. #1
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532

    InternetConnect fails

    In a program I am making I decided to use the wininet library. So I linked it and got everything set up. Then I tried to connect to google using InternetConnect. I know I saw something on MSDN that says if you use the user part blank it will return an error if you are using the HTTP protocol, which I am. Here is the parameters I passed to InternetConnect:
    Code:
    InternetConnect(NULL,"www.google.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
    The two NULL parameters after INTERNET_DEFAULT_HTTP_PORT are the user and password. I did try plugging "guest" into those but still failed. By failing I don't mean not compiling I mean returning a NULL handle. Is there a certain thing I need to send as user or am I doing something wrong? Thanks.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Well saying which error(s) you've got rather than just "doesn't work" would help.

    As would a bit of code around the single function call, which is no doubt the same as the example line on MSDN.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You have to call InternetOpen first and supply the returned handle to InternetConnect. WinINet sample here.

  4. #4
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Yes, thanks anonytmouse that was the problem. I didn't supply any code because I had a feeling it was a simple problem like that. If it turned out to be more complex(which it wasn't) I would have supplied more information. Salem I don't see where I put "doesn't work" in my first post, oh yeah that's because I DIDN'T! I said it returned a NULL handle not an error.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    So you did this?

    Code:
    InternetOpen(TEXT("www.google.com"), PRE_CONFIG_INTERNET_ACCESS, NULL, NULL, 0));
    InternetConnect(NULL,"www.google.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SER  VICE_HTTP,0,0);

  6. #6
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    I did this:
    Code:
    HINTERNET IntOp=InternetOpen("NewBrowserTool",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,INTERNET_FLAG_ASYNC);
    if(IntOp!=NULL)
    {
    HINTERNET hGoogle=InternetConnect(IntOp,"www.google.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,NULL,NULL);
    }
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 06-24-2009, 09:49 AM
  2. Mac - File locking with fcntl() fails on shared volumes!?
    By idelovski in forum Linux Programming
    Replies: 3
    Last Post: 11-10-2008, 07:37 PM
  3. Replies: 0
    Last Post: 05-23-2005, 11:39 AM
  4. wininet (internetconnect)
    By jabroni77 in forum Networking/Device Communication
    Replies: 0
    Last Post: 05-19-2005, 07:29 AM
  5. CFrameWnd::AssertValid() fails in debug mode
    By s_k in forum Windows Programming
    Replies: 1
    Last Post: 02-16-2003, 09:32 AM