Subversion Repositories userdetect2

Rev

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