2 SPP
\83v
\83\89\83O
\83C
\83\93\82ð
\88µ
\82¤
\82½
\82ß
\82Ì
\83N
\83\89\83X
9 uses Windows, SysUtils, Classes, Graphics;
12 ESppException = class(Exception);
14 TPluginFunction = (pfConfigure, pfSurfaceImage, pfSurfaceList);
15 TPluginFunctions = set of TPluginFunction;
17 TScope = 0..1; //
\83S
\81[
\83X
\83g
\83X
\83R
\81[
\83v
18 TScopes = set of TScope;
20 TSppGetVersionFunc = function(Name: PChar; NameLen: integer;
21 var Version: integer; var CanConfigure: boolean): integer; cdecl;
23 //
\83L
\83\83\83b
\83V
\83\85\83f
\81[
\83^
\82Æ
\82È
\82é1
\96\87\82Ì
\83T
\81[
\83t
\83B
\83X
\83v
\83\8c\83r
\83\85\81[
\89æ
\91\9c\82ð
24 //
\95Û
\8e\9d\82·
\82é
\83N
\83\89\83X
25 //
\89æ
\91\9c\82»
\82Ì
\82à
\82Ì
\82Æ
\81A
\82»
\82ê
\82Ì
\83S
\81[
\83X
\83g
\96¼
\81ASurfaceKey
\82ð
\95Û
\8e\9d\82·
\82é
26 TSppImage = class(TObject)
31 procedure SetBitmap(const Value: TBitmap);
32 procedure SetGhost(const Value: String);
33 procedure SetSurfaceKey(const Value: String);
35 function SurfaceKeyMatchTest(Surface: integer; AScope: TScope): boolean;
38 destructor Destroy; override;
39 function KeyMatchTest(const Ghost: String;
40 Surface: integer; Scope: TScope): boolean;
41 property Ghost: String read FGhost write SetGhost;
42 property SurfaceKey: String read FSurfaceKey write SetSurfaceKey;
43 property Bitmap: TBitmap read FBitmap write SetBitmap;
46 TSppImplementation = class;
48 //
\83v
\83\89\83O
\83C
\83\93\82ð
\95\
\82·
\83N
\83\89\83X
49 //
\83v
\83\89\83O
\83C
\83\93\82ðLoadModule
\82µ
\81A
\8eí
\97Þ
\82â
\83o
\81[
\83W
\83\87\83\93\82ð
\94»
\95Ê
\82µ
\82Ä
50 //
\93K
\90Ø
\82ÉTSppImplementation(
\82ð
\8cp
\8f³
\82µ
\82½
\82¢
\82¸
\82ê
\82©
\82Ì
\8bï
\8fÛ
\83N
\83\89\83X)
\82ð
52 TSppPlugin = class(TObject)
54 FPluginName: String; //
\83v
\83\89\83O
\83C
\83\93\82Ì
\96¼
\91O(## Loader)
55 FModuleName: String; // DLL
\82Ì
\96¼
\91O(*.dll)
56 FImplementation: TSppImplementation; //
\83v
\83\89\83O
\83C
\83\93\82Ì
\8eÀ
\91\95
58 FPluginFunctions: TPluginFunctions;
60 procedure CreateImplementation;
62 constructor Create(const ModuleName: String);
63 destructor Destroy; override;
64 property ModuleName: String read FModuleName;
65 property PluginName: String read FPluginName;
66 function GetImage(const Ghost: String;
67 Surface: integer; Scope: TScope): TSppImage;
68 property Handle: THandle read FHandle;
69 property PluginFunctions: TPluginFunctions read FPluginFunctions;
73 //
\83v
\83\89\83O
\83C
\83\93\8eÀ
\91\95\82Ì
\83x
\81[
\83X
\83N
\83\89\83X(
\92\8a\8fÛ
\83N
\83\89\83X)
74 //
\82±
\82Ì
\95\94\95ª
\82ÅSPP1.0
\82ÆSPP2.0
\82ÌAPI
\82Ì
\88á
\82¢
\82ð
\92\8a\8fÛ
\89»
\82·
\82é
75 TSppImplementation = class(TObject)
79 constructor Create(Owner: TSppPlugin); virtual;
80 procedure Load; virtual; abstract;
81 function GetImage(const Ghost: String;
82 Surface: integer; Scope: TScope): TSppImage; virtual; abstract;
83 procedure Unload; virtual; abstract;
84 property Owner: TSppPlugin read FOwner;
85 procedure Configure; virtual; abstract;
88 { SPP Version1
\97p
\82Ì
\8c^ }
89 TSpp1LoadProc = procedure(Path: PChar); cdecl;
90 TSpp1UnloadProc = procedure; cdecl;
91 TSpp1GetImageFunc = function(Ghost: PChar; Surface: integer;
92 H: HBITMAP): integer; cdecl;
93 TSpp1GetImageSizeFunc = function(Ghost: PChar; Surface: integer;
94 var w, h: integer): integer; cdecl;
95 TSpp1ConfigureProc = procedure; cdecl;
97 TSppImplementation1 = class(TSppImplementation)
99 //
\8aÖ
\90\94\81E
\8eè
\91±
\82«
\95Ï
\90\94
100 FSppLoad: TSpp1LoadProc;
101 FSppUnload: TSpp1UnloadProc;
102 FSppGetImage: TSpp1GetImageFunc;
103 FSppGetImageSize: TSpp1GetImageSizeFunc;
104 FSppConfigure: TSpp1ConfigureProc;
106 function DoGetImage(const Ghost: String;
107 const Surface: integer; Bitmap: TBitmap): boolean;
109 constructor Create(Owner: TSppPlugin); override;
110 procedure Load; override;
111 function GetImage(const Ghost: String;
112 Surface: integer; Scope: TScope): TSppImage; override;
113 procedure Unload; override;
114 procedure Configure; override;
122 procedure TSppPlugin.Configure;
124 FImplementation.Configure;
127 constructor TSppPlugin.Create(const ModuleName: String);
129 FModuleName := ModuleName;
130 FHandle := LoadLibrary(PChar(FModuleName));
132 raise ESppException.CreateFmt('Error loading %s', [FModuleName])
135 CreateImplementation;
136 FImplementation.Load;
140 procedure TSppPlugin.CreateImplementation;
141 var GetVersion: TSppGetVersionFunc;
142 DLLName: array [0..255] of char;
144 CanConfigure: boolean;
146 GetVersion := GetProcAddress(FHandle, 'GetVersion');
147 if (@GetVersion = nil) then
148 raise ESppException.CreateFmt('%s is not a valid SPP module', [FModuleName]);
150 GetVersion(@DLLName, sizeof(DLLName), Version, CanConfigure);
152 1: FImplementation := TSppImplementation1.Create(Self);
153 // 2: FImplementation := TSppImplementation.Create(Self);
155 raise ESppException.CreateFmt('Module %s returned '+
156 'unsupported version number(%d)', [FModuleName, Version]);
158 FPluginName := DLLName;
160 FPluginFunctions := [pfConfigure]
162 FPluginFunctions := [];
165 destructor TSppPlugin.Destroy;
167 if FImplementation <> nil then
168 FImplementation.UnLoad;
169 FImplementation.Free;
170 if not FreeLibrary(FHandle) then
171 raise ESppException.CreateFmt('Error unloading module %s', [FModuleName]);
175 function TSppPlugin.GetImage(const Ghost: String;
176 Surface: integer; Scope: TScope): TSppImage;
178 Result := FImplementation.GetImage(Ghost, Surface, Scope);
181 { TSppImplementation }
183 constructor TSppImplementation.Create(Owner: TSppPlugin);
190 constructor TSppImage.Create;
192 FBitmap := TBitmap.Create;
195 destructor TSppImage.Destroy;
201 function TSppImage.KeyMatchTest(const Ghost: String; Surface: integer;
202 Scope: TScope): boolean;
204 //
\8ew
\92è
\82³
\82ê
\82½
\83S
\81[
\83X
\83g
\81E
\83T
\81[
\83t
\83B
\83XID
\81E
\83X
\83R
\81[
\83v
\82Ì
205 //
\83T
\81[
\83t
\83B
\83X
\82Ì
\83v
\83\8c\83r
\83\85\81[
\82É
\81A
\82±
\82Ì
\89æ
\91\9c\82ª
\8eg
\82¦
\82é
\82©?
206 Result := (Self.Ghost = Ghost) and SurfaceKeyMatchTest(Surface, Scope);
209 procedure TSppImage.SetBitmap(const Value: TBitmap);
211 FBitmap.Assign(Value);
214 procedure TSppImage.SetGhost(const Value: String);
219 procedure TSppImage.SetSurfaceKey(const Value: String);
221 FSurfaceKey := Value;
224 function TSppImage.SurfaceKeyMatchTest(Surface: integer;
225 AScope: TScope): boolean;
228 Token, SurfaceIDList, ScopeKey: String;
229 FromID, ToID: integer;
230 const SyntaxError = 'Syntax error found in SurfaceKey "%s"';
233 p := Pos(',', SurfaceKey);
235 raise ESppException.CreateFmt(SyntaxError, [SurfaceKey]);
236 SurfaceIDList := Copy(SurfaceKey, 1, p-1);
237 ScopeKey := Copy(SurfaceKey, p+1, High(integer));
238 if (ScopeKey <> '*') and (ScopeKey <> IntToStr(AScope)) then
240 if SurfaceIDList = '*' then
245 Tokens := TStringList.Create;
248 Tokens.Delimiter := '&';
249 Tokens.DelimitedText := SurfaceIDList;
250 for i := 0 to Tokens.Count-1 do
253 p := Pos('-', Token);
256 FromID := StrToInt(Copy(Token, 1, p));
257 ToID := StrToInt(Copy(Token, p+1, High(integer)));
260 FromID := StrToInt(Token);
263 if (FromID <= Surface) and (Surface <= ToID) then
271 raise ESppException.CreateFmt(SyntaxError, [SurfaceKey]);
278 { TSppImplementation1 }
280 procedure TSppImplementation1.Configure;
286 constructor TSppImplementation1.Create(Owner: TSppPlugin);
292 function TSppImplementation1.DoGetImage(const Ghost: String;
293 const Surface: integer; Bitmap: TBitmap): boolean;
296 H := Bitmap.ReleaseHandle;
297 Result := FSppGetImage(PChar(Ghost), Surface, H) = 0;
301 function TSppImplementation1.GetImage(const Ghost: String;
302 Surface: integer; Scope: TScope): TSppImage;
303 var Width, Height: integer;
309 if Surface < 0 then Exit;
310 if FSppGetImageSize(PChar(Ghost), Surface, Width, Height) <> 0 then
312 TmpBitmap := TBitmap.Create;
314 TmpBitmap.Width := Width;
315 TmpBitmap.Height := Height;
316 if DoGetImage(Ghost, Surface, TmpBitmap) then
318 Result := TSppImage.Create;
319 Result.Bitmap := TmpBitmap;
320 Result.Ghost := Ghost;
321 Result.SurfaceKey := Format('%d,*', [Surface]); // Any scope
328 procedure TSppImplementation1.InitProcs;
331 SSppUnload = 'Unload';
332 SSppGetVersion = 'GetVersion';
333 SSppGetImage = 'GetImage';
334 SSppGetImageSize = 'GetImageSize';
335 SSppConfigure = 'Configure';
337 // Load DLL procedures
338 FSppLoad := GetProcAddress(Owner.Handle, SSppLoad);
339 FSppUnload := GetProcAddress(Owner.Handle, SSppUnload);
340 FSppGetImage := GetProcAddress(Owner.Handle, SSppGetImage);
341 FSppGetImageSize := GetProcAddress(Owner.Handle, SSppGetImageSize);
342 FSppConfigure := GetProcAddress(Owner.Handle, SSppConfigure);
344 if (@FSppLoad = nil) or (@FSppUnload = nil) or (@FSppGetImage = nil) or
345 (@FSppGetImageSize = nil) or (@FSppConfigure = nil) then
347 raise ESppException.Create('Error Getting Procedure Address');
351 procedure TSppImplementation1.Load;
354 FSppLoad(PChar(ExtractFilePath(Owner.ModuleName)));
357 procedure TSppImplementation1.Unload;