日期:2014-05-17  浏览次数:20956 次

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