Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I am writing a console application to set the proxy settings in WM 6.5 device using an API InternetSetOption. Can you tell me how can use this API to set the following settings in the device.

1. Proxy Server
2. Proxy Override
3. Proxy ID
4. Address

I have implemented the following code:
C++
// proxy_add.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include "Wininet.h"

BOOL SetConnectionOptions()
{
    INTERNET_PER_CONN_OPTION_LIST list;
    BOOL    bReturn;
    DWORD   dwBufSize = sizeof(list);

    // Fill the list structure.
    list.dwSize = sizeof(list);

    // NULL == LAN, otherwise connectoid name.
    list.pszConnection = NULL;

    // Set three options.
    list.dwOptionCount = 2;
    list.pOptions = new INTERNET_PER_CONN_OPTION[2];

    // Ensure that the memory was allocated.
    if(NULL == list.pOptions)
    {
        // Return FALSE if the memory wasn't allocated.
        return FALSE;
    } 

    // Set proxy name.
    list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
    list.pOptions[0].Value.pszValue = TEXT("http://proxy:80");

    // Set proxy override.
    list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
    list.pOptions[1].Value.pszValue = TEXT("local");

	// Set the options on the connection.
    bReturn = InternetSetOption(NULL,INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);

    // Free the allocated memory.
    delete [] list.pOptions;
    return bReturn;
}

int _tmain(int argc, _TCHAR* argv[])
{
	SetConnectionOptions();
	return 0;
}

But things are not working. It is not giving any error.
Posted
Updated 7-Sep-10 7:56am
v3

1 solution

you need this code

C#
S
list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT |
    PROXY_TYPE_PROXY;

  // Set proxy name.
    list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
    list.pOptions[1].Value.pszValue = TEXT("http://proxy:80");
 
    // Set proxy override.
    list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
    list.pOptions[2].Value.pszValue = TEXT("local");
// Set the options on the connection.

bReturn = InternetSetOption(NULL,
    INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900