using System.Runtime.InteropServices;namespace windows_API
{
public partial class GetSystemForm : Form
{
public GetSystemForm()
{
InitializeComponent();
}
[DllImport("kernel32.dll")]
private static extern bool GetComputerName(StringBuilder lpBuffer, int nsize);
private void GetSystemDirectoryForm_Load(object sender, EventArgs e)
{
StringBuilder buffComputer = new StringBuilder(100);
GetComputerName(buffComputer, 100);
//这里提示 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
}
}
}
{
public partial class GetSystemForm : Form
{
public GetSystemForm()
{
InitializeComponent();
}
[DllImport("kernel32.dll")]
private static extern bool GetComputerName(StringBuilder lpBuffer, int nsize);
private void GetSystemDirectoryForm_Load(object sender, EventArgs e)
{
StringBuilder buffComputer = new StringBuilder(100);
GetComputerName(buffComputer, 100);
//这里提示 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
}
}
}
解决方案 »
- 如图,关于.net连接数据库时候出现这个问题是什么原因呢?
- C# winform 输入完了后 textbox控件 触发什么事件比较好???
- 用WebService 时遇到的问题上来问下 有图(100分)
- 为何显示不出图片?或者保存生成的图片?
- 求助 c# adsl拨号类 无法断开
- 200分送上,winform中如何用一个程序去控制另一个程序
- winform中c#复合自定义控件的问题
- C#范型之间怎样转换? 比如List<BaseClass>转为List<DerivedClass>
- 200分, 请教C#中一个正则匹配(或者替换)的写法
- 关于连接串的问题,紧急求救!
- 我想用线程开起音乐,但怎么能让它停止呢
- 鼠标单击事件
[DllImport("kernel32.dll")]
static extern bool GetComputerName(IntPtr p , ref int lpnSize);
IntPtr p = Marshal.AllocHGlobal(128);
int len = 128;
GetComputerName(p, ref len);