CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Posts
    290

    InternetQueryOption and InternetSetOption

    I try to set internet option of
    INTERNET_OPTION_RECEIVE_TIMEOUT by following code.
    it return error code 12010.

    I think that it maybe the handle is not the right type of handle .And try another handle return by InternetOpenUrl but failed also.
    And I tried INTERNET_OPTION_CONNECT_TIMEOUT also but failed.

    both handle is right.

    thank you .



    m_hSession = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);

    char szTimeout[10];
    memset(szTimeout,0,10);
    DWORD dwSize=10;
    BOOL bSetInternetOption ;
    bSetInternetOption = InternetQueryOption(m_hSession,INTERNET_OPTION_CONNECT_TIMEOUT ,szTimeout,&dwSize);
    long lTimeout = atol(szTimeout);
    memset(szTimeout,0,10);
    memcpy(szTimeout,"3000",5);
    bSetInternetOption = InternetSetOption(m_hSession,INTERNET_OPTION_CONNECT_TIMEOUT ,szTimeout,5);
    strTimeout.Format("%d,%d,%x",bSetInternetOption,GetLastError(),GetLastError());
    bSetInternetOption = InternetQueryOption(m_hSession,INTERNET_OPTION_CONNECT_TIMEOUT ,szTimeout,&dwSize);
    lTimeout = atol(szTimeout);

  2. #2
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573
    Hi,

    Code:
    12010               ERROR_INTERNET_BAD_OPTION_LENGTH
    The length of an option supplied to InternetQueryOption
    or InternetSetOption is incorrect for the type of option specified.
    Check your code again.
    Regards,

    Emanuel Vaduva

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556
    You need to call InternetQueryOption twice, the first time passing in a NULL pointer to find out how big a buffer the API needs, and the second time with a buffer of size returned by the first call. Since you're getting a 12010 error, your guess-timate of 10 for szTimeout must not be big enough. Try:

    DWORD dwSize=0;
    BOOL bSetInternetOption ;
    bSetInternetOption = InternetQueryOption(m_hSession,INTERNET_OPTION_CON
    NECT_TIMEOUT ,NULL,&dwSize);

    char* szTimeout=new char[dwSize];
    memset(szTimeout,0,dwSize);


    bSetInternetOption = InternetQueryOption(m_hSession,INTERNET_OPTION_CON
    NECT_TIMEOUT ,szTimeout,&dwSize);

    long lTimeout = atol(szTimeout);

    delete[] szTimeout;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured