using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace GetLocalIpApp
{
class Program
{
[DllImport("kernel32.dll")]
static extern bool GetComputerName(IntPtr p, ref int lpnSize);
static void Main(string[] args)
{
string strLocalName = LocalComputerName();
Console.WriteLine(strLocalName);
Console.Read();
}
static string LocalComputerName()
{
IntPtr p = Marshal.AllocHGlobal(128);
int len = 128;
GetComputerName(p, ref len);
string strName = Marshal.PtrToStringAnsi(p);
//释放指针占用的内存
Marshal.FreeHGlobal(p);
return strName;
}
}
}c#.net使用WinAPI: GetComputerName - 获取计算机名称
最新推荐文章于 2021-06-16 02:01:36 发布
本文介绍了如何使用C#中的DllImport方法从kernel32.dll获取本地计算机名称,并进而获取本地IP地址。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

412

被折叠的 条评论
为什么被折叠?



