Subversion Repositories userdetect2

Rev

Rev 69 | Go to most recent revision | Details | 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
10
  Windows, Classes, UD2_PluginIntf;
11
 
12
(*
13
function WritePascalStringToPointerA(lpDestination: LPSTR; cchSize: DWORD;
14
  stSource: AnsiString): UD2_STATUSCODE;
15
*)
16
 
17
function WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
18
  stSource: WideString): UD2_STATUSCODE;
19
 
20
(*
21
function WriteStringListToPointerA(lpDestination: LPSTR; cchSize: DWORD;
22
  slSource: TStrings): UD2_STATUSCODE;
23
*)
24
 
25
function WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
26
  slSource: TStrings): UD2_STATUSCODE;
27
 
28
implementation
29
 
30
uses
31
  Math;
32
 
33
(*
34
function WritePascalStringToPointerA(lpDestination: LPSTR; cchSize: DWORD;
35
  stSource: AnsiString): UD2_STATUSCODE;
36
var
37
  cchSource: DWORD;
38
begin
39
  if cchSize = 0 then
40
  begin
41
    result := STATUS_INVALID_ARGS;
42
    Exit;
43
  end;
44
  if stSource = '' then
45
  begin
46
    ZeroMemory(lpDestination, SizeOf(AnsiChar));
47
    result := STATUS_OK;
48
  end
49
  else
50
  begin
51
    CopyMemory(lpDestination, @stSource[1], cchSize*SizeOf(AnsiChar));
52
    cchSource := Cardinal(Length(stSource));
53
    if cchSource >= cchSize then
54
    begin
55
      result := STATUS_BUFFER_TOO_SMALL;
56
      ZeroMemory(lpDestination+(cchSize-1)*SizeOf(AnsiChar), SizeOf(AnsiChar));
57
    end
58
    else
59
    begin
60
      result := STATUS_OK;
61
    end;
62
  end;
63
end;
64
*)
65
 
66
function WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
67
  stSource: WideString): UD2_STATUSCODE;
68
var
69
  cchSource: DWORD;
70
  cchCopy: DWORD;
71
begin
72
  if cchSize = 0 then
73
  begin
74
    result := UD2_STATUS_INVALID_ARGS;
75
    Exit;
76
  end;
77
 
78
  cchSource := Cardinal(Length(stSource));
79
  cchCopy   := Cardinal(Min(cchSource, cchSize));
80
  if cchCopy > 0 then
81
  begin
82
    CopyMemory(lpDestination, @stSource[1], cchCopy*SizeOf(WideChar));
83
  end;
84
  ZeroMemory(lpDestination+cchCopy*SizeOf(WideChar), SizeOf(WideChar));
85
 
86
  if cchSource >= cchSize then
87
  begin
88
    result := UD2_STATUS_BUFFER_TOO_SMALL;
89
  end
90
  else
91
  begin
92
    result := UD2_STATUS_OK;
93
  end;
94
end;
95
 
96
(*
97
function WriteStringListToPointerA(lpDestination: LPSTR; cchSize: DWORD;
98
  slSource: TStrings): UD2_STATUSCODE;
99
var
100
  stSource: AnsiString;
101
  i: integer;
102
begin
103
  stSource := '';
104
  for i := 0 to slSource.Count-1 do
105
  begin
106
    if i > 0 then stSource := stSource + UD2_MULTIPLE_ITEMS_DELIMITER;
107
    stSource := stSource + slSource.Strings[i];
108
  end;
109
  result := WritePascalStringToPointerA(lpDestination, cchSize, stSource);
110
end;
111
*)
112
 
113
function WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
114
  slSource: TStrings): UD2_STATUSCODE;
115
var
116
  stSource: WideString;
117
  i: integer;
118
begin
119
  stSource := '';
120
  for i := 0 to slSource.Count-1 do
121
  begin
122
    if i > 0 then stSource := stSource + UD2_MULTIPLE_ITEMS_DELIMITER;
123
    stSource := stSource + slSource.Strings[i];
124
  end;
125
  result := WritePascalStringToPointerW(lpDestination, cchSize, stSource);
126
end;
127
 
128
end.