修改注册表

bupo_007 2008-03-24 11:22:06
using System;
using System.Collections;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Microsoft.Win32;

namespace TestBlog
{
class Program
{
[DllImport(@"wininet",
SetLastError = true,
CharSet = CharSet.Auto,
EntryPoint = "InternetSetOption",
CallingConvention = CallingConvention.StdCall)]

public static extern bool InternetSetOption
(
int hInternet,
int dmOption,
IntPtr lpBuffer,
int dwBufferLength
);


public static void SetProxy(string proxy)
{
//打开注册表
RegistryKey regKey = Registry.CurrentUser;
string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
//更改健值,设置代理,
optionKey.SetValue("ProxyEnable", 1);
optionKey.SetValue("ProxyServer", proxy);

//激活代理设置
InternetSetOption(0, 39, IntPtr.Zero, 0);
InternetSetOption(0, 37, IntPtr.Zero, 0);
}


}

弱弱的问一下这一段
[DllImport(@"wininet",
SetLastError = true,
CharSet = CharSet.Auto,
EntryPoint = "InternetSetOption",
CallingConvention = CallingConvention.StdCall)]
在上面的代码是什么作用,什么意思
还有下面的两句

InternetSetOption(0, 39, IntPtr.Zero, 0);
InternetSetOption(0, 37, IntPtr.Zero, 0);
是如何激活设置的
public static extern bool InternetSetOption
(
int hInternet,
int dmOption,
IntPtr lpBuffer,
int dwBufferLength
);这里只提供了个函数签名,没有提供函数实现,为什么?

各位大侠,谢了
...全文
46 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dancingbit 2008-03-24
  • 打赏
  • 举报
回复
[DllImport(@"wininet", //库文件名
SetLastError = true,
CharSet = CharSet.Auto, //字符集
EntryPoint = "InternetSetOption", //函数进入点
CallingConvention = CallingConvention.StdCall)] //调用规则

至于如何激活设置,看那个API函数的了。
因为这个函数是从Windows库中导入的,所以,这里面是肯定没有实现代码的。
bupo_007 2008-03-24
  • 打赏
  • 举报
回复
能不能具体点说?
谢谢
dancingbit 2008-03-24
  • 打赏
  • 举报
回复
从Windows的库中导入的API函数,至于DllImport后面的内容,基本上是:库文件名、字符集、函数进入点、调用规则等。

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧