Subversion Repositories userdetect2

Rev

Rev 71 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. unit UD2_PluginUtils;
  2.  
  3. interface
  4.  
  5. {$IF CompilerVersion >= 25.0}
  6. {$LEGACYIFEND ON}
  7. {$IFEND}
  8.  
  9. uses
  10.   Windows, Classes, UD2_PluginIntf, UD2_PluginStatus;
  11.  
  12. function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
  13.   stSource: WideString): UD2_STATUS;
  14.  
  15. function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
  16.   slSource: TStrings): UD2_STATUS;
  17.  
  18. implementation
  19.  
  20. uses
  21.   Math;
  22.  
  23. function UD2_IsMultiLineW(s: WideString): boolean;
  24. var
  25.   i: integer;
  26.   c: WideChar;
  27. begin
  28.   for i := 1 to Length(s) do
  29.   begin
  30.     c := s[i];
  31.     if c = UD2_MULTIPLE_ITEMS_DELIMITER then //if (c = #10) or (c = #13) then
  32.     begin
  33.       Result := true;
  34.       Exit;
  35.     end;
  36.   end;
  37.   Result := false;
  38. end;
  39.  
  40. function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
  41.   stSource: WideString): UD2_STATUS;
  42. var
  43.   cchSource: DWORD;
  44.   cchCopy: DWORD;
  45. begin
  46.   if cchSize = 0 then
  47.   begin
  48.     result := UD2_STATUS_FAILURE_INVALID_ARGS;
  49.     Exit;
  50.   end;
  51.  
  52.   cchSource := Cardinal(Length(stSource));
  53.   cchCopy   := Cardinal(Min(cchSource, cchSize));
  54.   if cchCopy > 0 then
  55.   begin
  56.     CopyMemory(lpDestination, @stSource[1], cchCopy*SizeOf(WideChar));
  57.   end;
  58.   lpDestination[cchCopy] := #0;
  59.  
  60.   if cchSource >= cchSize then
  61.     result := UD2_STATUS_FAILURE_BUFFER_TOO_SMALL
  62.   else if stSource = '' then
  63.     result := UD2_STATUS_NOTAVAIL_UNSPECIFIED
  64.   else if UD2_IsMultiLineW(stSource) then
  65.     result := UD2_STATUS_OK_MULTILINE
  66.   else
  67.     result := UD2_STATUS_OK_SINGLELINE;
  68. end;
  69.  
  70. function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
  71.   slSource: TStrings): UD2_STATUS;
  72. var
  73.   stSource: WideString;
  74.   i: integer;
  75. begin
  76.   stSource := '';
  77.   for i := 0 to slSource.Count-1 do
  78.   begin
  79.     if i > 0 then stSource := stSource + UD2_MULTIPLE_ITEMS_DELIMITER;
  80.     stSource := stSource + slSource.Strings[i];
  81.   end;
  82.   result := UD2_WritePascalStringToPointerW(lpDestination, cchSize, stSource);
  83. end;
  84.  
  85. end.
  86.