Subversion Repositories userdetect2

Rev

Rev 69 | Go to most recent revision | 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
 
69 daniel-mar 12
function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
13
  stSource: WideString): UD2_STATUS;
68 daniel-mar 14
 
69 daniel-mar 15
function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
16
  slSource: TStrings): UD2_STATUS;
68 daniel-mar 17
 
18
implementation
19
 
20
uses
21
  Math;
22
 
69 daniel-mar 23
function UD2_IsMultiLineW(s: WideString): boolean;
68 daniel-mar 24
var
69 daniel-mar 25
  i: integer;
26
  c: WideChar;
68 daniel-mar 27
begin
69 daniel-mar 28
  for i := 1 to Length(s) do
68 daniel-mar 29
  begin
69 daniel-mar 30
    c := s[i];
31
    if c = UD2_MULTIPLE_ITEMS_DELIMITER then //if (c = #10) or (c = #13) then
68 daniel-mar 32
    begin
69 daniel-mar 33
      Result := true;
34
      Exit;
68 daniel-mar 35
    end;
36
  end;
69 daniel-mar 37
  Result := false;
68 daniel-mar 38
end;
39
 
69 daniel-mar 40
function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
41
  stSource: WideString): UD2_STATUS;
68 daniel-mar 42
var
43
  cchSource: DWORD;
44
  cchCopy: DWORD;
45
begin
46
  if cchSize = 0 then
47
  begin
71 daniel-mar 48
    result := UD2_STATUS_FAILURE_INVALID_ARGS;
68 daniel-mar 49
    Exit;
50
  end;
69 daniel-mar 51
 
68 daniel-mar 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;
69 daniel-mar 58
  lpDestination[cchCopy] := #0;
68 daniel-mar 59
 
60
  if cchSource >= cchSize then
71 daniel-mar 61
    result := UD2_STATUS_FAILURE_BUFFER_TOO_SMALL
69 daniel-mar 62
  else if stSource = '' then
63
    result := UD2_STATUS_NOTAVAIL_UNSPECIFIED
64
  else if UD2_IsMultiLineW(stSource) then
65
    result := UD2_STATUS_OK_MULTILINE
68 daniel-mar 66
  else
69 daniel-mar 67
    result := UD2_STATUS_OK_SINGLELINE;
68 daniel-mar 68
end;
69
 
69 daniel-mar 70
function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
71
  slSource: TStrings): UD2_STATUS;
68 daniel-mar 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;
69 daniel-mar 82
  result := UD2_WritePascalStringToPointerW(lpDestination, cchSize, stSource);
68 daniel-mar 83
end;
84
 
85
end.