GetComputerName函数的调用
我用VB.NET2010写以下代码时,为什么会提示"试图读写受保护的内存"错误?
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim l_Name As String
l_Name = Space(256)
Call GetComputerName(l_Name, 256)
[解决办法]
Long 改为 Integer
更方便的方法:
My.Computer.Name 或 Environment.MachineName