-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDdeServer.pas
More file actions
111 lines (90 loc) · 2.88 KB
/
DdeServer.pas
File metadata and controls
111 lines (90 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
(*
Greenfish Icon Editor Pro
Copyright (c) 2012-13 B. Szalkai
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
unit DdeServer;
{$IFNDEF WINDOWS}
{$WARNING DdeServer: unit is specific to Windows}
interface
implementation
{$ELSE}
interface
uses
Windows, Messages, LclIntf, LclType, SysUtils, ieShared, DocClass, Main;
const
sDDEServerName = 'GFIEPro';
sDDETopic = 'System';
var
ddeInited: boolean = False;
ddeInst: Cardinal;
ddeServerName: THandle;
ddeTopic: THandle;
implementation
procedure ddeParseString(Message: PChar; var cmd, param: string);
var
p1, p2, p3, p4: PChar;
begin
// text between [ and ( : cmd
p1 := FindInPChar(Message, '[');
inc(p1);
p2 := FindInPChar(p1, '(');
// text between " and " : param
p3 := FindInPChar(p2, '"');
inc(p3);
p4 := FindInPChar(p3, '"');
SetLength(cmd, p2-p1);
Move(p1^, cmd[1], Length(cmd));
cmd := UpperCase(cmd);
SetLength(param, p4-p3);
Move(p3^, param[1], Length(param));
end;
function ddeCallback(uType, uFmt: UINT; hConv, hsz1, hsz2, hData: THandle;
dwData1, dwData2: DWORD): THandle; stdcall;
var
szExecute: array of char;
cmd, param: string;
begin
Result := 0;
case uType of
XTYP_CONNECT: Result := Ord((hsz1 = ddeTopic) and (hsz2 = ddeServerName));
XTYP_EXECUTE: begin
SetLength(szExecute, DdeGetData(hData, nil, 0, 0) + 10);
FillChar(szExecute[0], Length(szExecute), #0);
DdeGetData(hData, @szExecute[0], Length(szExecute), 0);
ddeParseString(@szExecute[0], cmd, param);
if cmd = 'OPEN' then frmMain.DoOpen(param);
end;
end;
end;
const
APPCMD_FILTERINITS = $20;
initialization
if DdeInitialize(@ddeInst, @ddeCallback, APPCMD_FILTERINITS, 0) = 0 then
begin
ddeServerName := DdeCreateStringHandle(ddeInst, sDDEServerName, CP_WINANSI);
ddeTopic := DdeCreateStringHandle(ddeInst, sDDETopic, CP_WINANSI);
// register server name
DdeNameService(ddeInst, ddeServerName, 0, DNS_REGISTER);
// success
ddeInited := True;
end;
finalization
if ddeInited then
begin
ddeInited := False;
DdeFreeStringHandle(ddeInst, ddeServerName);
DdeFreeStringHandle(ddeInst, ddeTopic);
DdeUninitialize(ddeInst);
end;
{$ENDIF}
end.