首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# API GetUserNName?该如何处理

2013-09-07 
C# API GetUserNName?代码贴上using Systemusing System.Collections.Genericusing System.Linqusing S

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的原因,我个人的理解是因为这个参数不是输入参数,它会返回结果。

热点排行