VC源代码如下,pNewAcl 用 & 取地址PACL pAcl        = NULL;
PACL pNewAcl     = NULL;
EXPLICIT_ACCESS ea;
BuildExplicitAccessWithName(&ea, szName, dwAccess, GRANT_ACCESS, 0);
ea.Trustee.TrusteeType = TRUSTEE_IS_USER;if(ERROR_SUCCESS != SetEntriesInAcl(1, &ea, pAcl, &pNewAcl)) 
{
     printf("ModifySecurity SetEntriesInAcl Failed");
     pNewAcl = NULL;
     __leave;
}[code]
但是为什么在delphi里,pNewAcl 加 @ 就错了呢?不加 @ 编译能通过,但是SetEntriesInAcl返回错误代码1332.
恳请高手解惑~ 
[code=Delphi(Pascal)]
if(ERROR_SUCCESS <> SetEntriesInAcl(1, @ea, pOAcl, @pNewAcl))   then
        begin
              showmessage('ModifySecurity: '+inttostr(GetLastError));
              showmessage('ModifySecurity SetEntriesInAcl Failed');
              pNewAcl := nil;
              goto CleanUP;
        end;

解决方案 »

  1.   

    function SetPhyscialMemorySectionCanBeWrited(hSection: THandle): boolean;label CleanUp;var  pDacl, pNewDacl: JwaWinNT.PACL;  pSD: JwaWinNT.PSECURITY_DESCRIPTOR;  dwRes: DWORD;  ea: EXPLICIT_ACCESS;begin  Result := false;  pDacl := nil; pNewDacl := nil; pSD := nil;  dwRes := GetSecurityInfo(hSection, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION,    nil, nil, @pDacl, nil, pSD);  if dwRes <> ERROR_SUCCESS then    begin      MessageDlg(Format('GetSecurityInfo Error %d', [dwRes]), mtError, [mbOK], 0);      goto CleanUp;    end;  ZeroMemory(@ea, sizeof(EXPLICIT_ACCESS));  ea.grfAccessPermissions := SECTION_MAP_WRITE;  ea.grfAccessMode := GRANT_ACCESS;  ea.grfInheritance := NO_INHERITANCE;  ea.Trustee.TrusteeForm := TRUSTEE_IS_NAME;  ea.Trustee.TrusteeType := TRUSTEE_IS_USER;  ea.Trustee.ptstrName := 'CURRENT_USER';  dwRes := SetEntriesInAcl(1, @ea, pDacl, pNewDacl);  if dwRes <> ERROR_SUCCESS then     begin       MessageDlg(Format('SetEntriesInAcl Error : %d', [dwRes]), mtError, [mbOK], 0);       goto CleanUp;     end;
      

  2.   

    多谢~
    顺便问一下  CreateFile 函数创建文件夹,该怎么设置参数?
      

  3.   

       这句提示错误 , pSD 这个参数好像有点问题?
      

  4.   

    CreateFile创建文件夹?MSDN上就有说明,百度也行
    http://baike.baidu.com/view/1288759.htm
    另外这个代码是我从网上找的一个无驱动进Ring0的代码
    http://kmdkit4d.net/dispbbs.do?boardId=8&ID=16&star=2