Different processing of Delphi handle and VC handle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.