ndkutils.pas 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. {
  2. FPC Utility Function for Native NT applications
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2009 by Sven Barth
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit NDKUtils;
  12. {.$H+}
  13. interface
  14. uses
  15. NDK;
  16. procedure ShortStrToNTStr(aStr: ShortString; var aNTStr: TNtUnicodeString);
  17. //procedure AnsiStrToNTStr(const aStr: String; var aNTStr: TNtUnicodeString);
  18. implementation
  19. procedure ShortStrToNTStr(aStr: ShortString; var aNTStr: TNtUnicodeString);
  20. var
  21. buf: Pointer;
  22. i: Integer;
  23. begin
  24. FillChar(aNTStr, SizeOf(TNtUnicodeString), 0);
  25. aNTStr.Length := Length(aStr) * 2;
  26. aNTStr.buffer := GetMem(aNTStr.Length);
  27. buf := aNTStr.buffer;
  28. for i := 1 to Length(aStr) do begin
  29. PWord(buf)^ := Word(aStr[i]);
  30. buf := Pointer(PtrUInt(buf) + SizeOf(Word));
  31. end;
  32. aNTStr.MaximumLength := aNTStr.Length;
  33. end;
  34. procedure InitializeObjectAttributes(var aObjectAttr: TObjectAttributes; aName: PNtUnicodeString; aAttributes: ULONG; aRootDir: THandle; aSecurity: Pointer);
  35. begin
  36. with aObjectAttr do begin
  37. Length := SizeOf(TObjectAttributes);
  38. RootDirectory := aRootDir;
  39. Attributes := aAttributes;
  40. ObjectName := aName;
  41. SecurityDescriptor := aSecurity;
  42. SecurityQualityOfService := Nil;
  43. end;
  44. end;
  45. end.