In Delphi, the magic changes, each variable name itself is a pointer, because the pointer syntax is not required. I do not know whether it is because of this cause the Delphi and VC handle the different handle.
This is Delphi's forced shutdown function, easy to use, call way: Windowsexit (Ewx_poweroff or Ewx_force)
functionWindowsexit (Rebootparam:longword): Boolean;varTtokenhd:thandle; Ttokenpvg:ttokenprivileges; Cbtpprevious:dword; Rttokenpvg:ttokenprivileges; Pcbtppreviousrequired:dword; Tpresult:boolean;ConstSe_shutdown_name='SeShutdownPrivilege';beginResult:=false; Try ifWin32platform = Ver_platform_win32_nt Then beginTpresult:=OpenProcessToken (GetCurrentProcess (), Token_adjust_privilegesortoken_query, TTOKENHD); ifTpresult Then beginTpresult:= Lookupprivilegevalue (Nil, Se_shutdown_name, ttokenpvg.privileges[0]. LUID); Ttokenpvg.privilegecount:=1; ttokenpvg.privileges[0]. Attributes: =se_privilege_enabled; Cbtpprevious:=SizeOf (RTTOKENPVG); Pcbtppreviousrequired:=0; ifTpresult Thenwindows.adjusttokenprivileges (Ttokenhd, False, TTOKENPVG, cbtpprevious, RTT OKENPVG, pcbtppreviousrequired); End; End; Result:= ExitWindowsEx (Rebootparam,0);//API except End;End;
But to translate this code into VC, but when passing handle, you must add a pointer reference, in order to eliminate the compilation error:
HANDLE Ttokenhd; BOOLTpresult = OpenProcessToken (GetCurrentProcess (), Token_adjust_privileges | Token_query, &TTOKENHD);//here, take the pointer . if(tpresult) {token_privileges TTOKENPVG, RTTOKENPVG; intcbtpprevious; Tpresult= Lookupprivilegevalue (NULL, Se_shutdown_name, &ttokenpvg.privileges[0]. LUID);//The CCC fetch address (pointer) should be the last element to functionTtokenpvg.privilegecount =1; ttokenpvg.privileges[0]. Attributes = se_privilege_enabled;//API is to change thisCbtpprevious =sizeof(RTTOKENPVG); DWORD pcbtppreviousrequired=0; if(Tpresult) {adjusttokenprivileges (TTOKENHD,false, &TTOKENPVG, Cbtpprevious, &RTTOKENPVG, &pcbtppreviousrequired);//here are three places to take pointers}} Res= ExitWindowsEx (Ewx_poweroff | Ewx_force,0);//API
Different processing of Delphi handle and VC handle