读书人

C# API GetUserNName?该如何处理

发布时间: 2013-09-07 14:12:45 作者: rapoo

C# API GetUserNName?
代码贴上


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace API_GetUserName_取得当前用户的名字
{
class Program
{
[DllImport("advapi32.dll", EntryPoint = "GetUserName")]
public static extern int GetUserName(
string lpBuffer,
ref int nSize
);

static void Main(string[] args)
{


string str = "0000000";
int b = 6;
int a=199;
b=GetUserName(str,ref a);
Console.WriteLine(str);
Console.WriteLine(a.ToString());
Console.WriteLine(b.ToString());
}
}
}




网上查了很多GetUsername的教程,不过给的都是GetComputerName 的
谁能告诉我GetUsername各参数怎么用啊?
我怎么就带不会来用户名啊
[解决办法]
_Out_ LPTSTR lpBuffer 是返回的name
[解决办法]
参数名无所谓,只要类型和个数匹配就行了。
这里不用string的原因,我个人的理解是因为这个参数不是输入参数,它会返回结果。

读书人网 >C#

热点推荐