Subversion Repositories userdetect2

Rev

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