user1357016
user1357016

Reputation: 1

How to set INTERNET_OPTION_MAX_CONNS_PER_SERVER option using InternetSetOption in c#?

I am new to .NET,c# and windows programming. I want to increase the max number of connections that the .NET web browser control can create per server. I found that by changing INTERNET_OPTION_MAX_CONNS_PER_SERVER option using InternetSetOption function in wininet.dll, i can do that.

I have done the below import.

[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool InternetSetOption(
    IntPtr hInternet,
    int dwOption,
    IntPtr lpBuffer,
    int lpdwBufferLength);

From the msdn doc, IntPtr lpBuffer should be an unsigned long int. Can anyone please tell me how i can create IntPtr for a unsigned long int variable.

Some sample invocation of InternetSetOption in c# to set max connections to 50 will be helpful.

PS: i cannot use change the registry settings using regedit.exe to increase the number of connections

Upvotes: 0

Views: 1290

Answers (1)

Tommaso Belluzzo
Tommaso Belluzzo

Reputation: 23675

[DllImport("WinInet.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
internal static extern Boolean InternetSetOption
(
    [In] IntPtr hInternet,
    [In] UInt32 dwOption,
    [In] IntPtr lpBuffer,
    [In] UInt32 lpdwBufferLength
);

Just try with:

NativeMethods.InternetSetOption(IntPtr.Zero, INTERNET_OPTION_MAX_CONNS_PER_SERVER, 10, 4);

You should not need a pointer here.

Upvotes: 0

Related Questions