Delphi - GetUserNameEx(学一下导出Windows API,以及Array Char充当缓冲区的用法,下标必须从零开始)

(*
* Author : http://www.michael-puff.de
* Date : 2006-03-29
* License : PUBLIC DOMAIN
*)
function GetUserNameEx(NameFormat: DWORD; lpNameBuffer: LPSTR; var nSize: DWORD): Boolean; stdcall; external
'secur32.dll' Name 'GetUserNameExA'; function GetLoggedOnUserNameEx(fFormat: DWORD; var Username: string): DWORD; const
NameUnknown = ; // Unknown name type.
NameFullyQualifiedDN = ; // Fully qualified distinguished name
NameSamCompatible = ; // Windows NT® 4.0 account name
NameDisplay = ; // A "friendly" display name
NameUniqueId = ; // GUID string that the IIDFromString function returns
NameCanonical = ; // Complete canonical name
NameUserPrincipal = ; // User principal name
NameCanonicalEx = ;
NameServicePrincipal = ; // Generalized service principal name
DNSDomainName = ; // DNS domain name, plus the user name var
Size : DWORD;
Buffer : array[..] of Char;
begin
Result := ;
Size := sizeof(Buffer);
if GetUserNameEx(fFormat, Buffer, Size) then
SetString(Username, Buffer, Size)
else
Result := GetLastError;
end; procedure TForm1.Button1Click(Sender: TObject);
var
Username : string;
err : DWORD;
begin
err := GetLoggedOnUserNameEx(, Username);
if err = 0 then
ShowMessage(Username)
else
ShowMessage(SysErrorMessage(err));
end;

http://www.michael-puff.de/Programmierung/Delphi/Code-Snippets/GetUserNameEx.shtml

上一篇:centos 下搭建 php环境(2) mysql 安装


下一篇:Unity5系列资源管理AssetBundle——打包