Subversion Repositories userdetect2

Rev

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