Subversion Repositories userdetect2

Rev

Rev 81 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
68 daniel-mar 1
unit UD2_PluginUtils;
2
 
3
interface
4
 
5
{$IF CompilerVersion >= 25.0}
6
{$LEGACYIFEND ON}
7
{$IFEND}
8
 
9
uses
71 daniel-mar 10
  Windows, Classes, UD2_PluginIntf, UD2_PluginStatus;
68 daniel-mar 11
 
80 daniel-mar 12
function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD; stSource: WideString): UD2_STATUS;
68 daniel-mar 13
 
80 daniel-mar 14
function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD; slSource: TStrings): UD2_STATUS;
68 daniel-mar 15
 
16
implementation
17
 
18
uses
19
  Math;
20
 
69 daniel-mar 21
function UD2_IsMultiLineW(s: WideString): boolean;
68 daniel-mar 22
var
69 daniel-mar 23
  i: integer;
24
  c: WideChar;
68 daniel-mar 25
begin
69 daniel-mar 26
  for i := 1 to Length(s) do
68 daniel-mar 27
  begin
69 daniel-mar 28
    c := s[i];
29
    if c = UD2_MULTIPLE_ITEMS_DELIMITER then //if (c = #10) or (c = #13) then
68 daniel-mar 30
    begin
69 daniel-mar 31
      Result := true;
32
      Exit;
68 daniel-mar 33
    end;
34
  end;
69 daniel-mar 35
  Result := false;
68 daniel-mar 36
end;
37
 
69 daniel-mar 38
function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
39
  stSource: WideString): UD2_STATUS;
68 daniel-mar 40
var
41
  cchSource: DWORD;
42
  cchCopy: DWORD;
43
begin
44
  if cchSize = 0 then
45
  begin
71 daniel-mar 46
    result := UD2_STATUS_FAILURE_INVALID_ARGS;
68 daniel-mar 47
    Exit;
48
  end;
69 daniel-mar 49
 
68 daniel-mar 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;
69 daniel-mar 56
  lpDestination[cchCopy] := #0;
68 daniel-mar 57
 
58
  if cchSource >= cchSize then
71 daniel-mar 59
    result := UD2_STATUS_FAILURE_BUFFER_TOO_SMALL
69 daniel-mar 60
  else if stSource = '' then
61
    result := UD2_STATUS_NOTAVAIL_UNSPECIFIED
62
  else if UD2_IsMultiLineW(stSource) then
63
    result := UD2_STATUS_OK_MULTILINE
68 daniel-mar 64
  else
69 daniel-mar 65
    result := UD2_STATUS_OK_SINGLELINE;
68 daniel-mar 66
end;
67
 
69 daniel-mar 68
function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
69
  slSource: TStrings): UD2_STATUS;
68 daniel-mar 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;
69 daniel-mar 80
  result := UD2_WritePascalStringToPointerW(lpDestination, cchSize, stSource);
68 daniel-mar 81
end;
82
 
83
end.