+++ /dev/null
-{
-
-SPP (Surface Preview Plugin) \83v\83\89\83O\83C\83\93\82ð\88µ\82¤\83N\83\89\83X
-
-}
-
-unit SppTypes;
-
-interface
-
-uses
- Windows, Forms, SysUtils, Graphics;
-
-type
- TSppLoadProc = procedure(Path: PChar); cdecl;
-
- TSppUnloadProc = procedure; cdecl;
-
- TSppGetVersionFunc = function(Name: PChar; NameLen: integer;
- var Version: integer; var CanConfigure: boolean): integer; cdecl;
-
- TSppGetImageFunc = function(Ghost: PChar; Surface: integer;
- H: HBITMAP): integer; cdecl;
-
- TSppGetImageSizeFunc = function(Ghost: PChar; Surface: integer;
- var w, h: integer): integer; cdecl;
-
- TSppConfigureProc = procedure; cdecl;
-
- TSurfacePreviewPlugin = class(TObject)
- private
- FModuleName: String;
- FHandle: THandle;
- // \8aÖ\90\94\81E\8eè\91±\82«\95Ï\90\94
- FSppLoad: TSppLoadProc;
- FSppUnload: TSppUnloadProc;
- FSppGetVersion: TSppGetVersionFunc;
- FSppGetImage: TSppGetImageFunc;
- FSppGetImageSize: TSppGetImageSizeFunc;
- FSppConfigure: TSppConfigureProc;
- //
- FDLLName: String;
- FVersion: integer;
- FCanConfigure: boolean;
- protected
- procedure InitProcs;
- procedure Load;
- public
- constructor Create(ModuleName: String);
- destructor Destroy; override;
- property ModuleName: String read FModuleName;
- property SppVersion: integer read FVersion;
- property CanConfigure: boolean read FCanConfigure;
- property DLLName: String read FDLLName;
- function GetImageSize(const Ghost: String; const Surface: integer;
- var Width, Height: integer): boolean;
- function GetImage(const Ghost: String; const Surface: integer;
- Bitmap: TBitmap): boolean;
- function SetSizeAndGetImage(const Ghost: String; const Surface: integer;
- Bitmap: TBitmap): boolean;
- procedure Configure;
- end;
-
- ESppException = class(Exception);
-
-const
- SSppLoad = 'Load';
- SSppUnload = 'Unload';
- SSppGetVersion = 'GetVersion';
- SSppGetImage = 'GetImage';
- SSppGetImageSize = 'GetImageSize';
- SSppConfigure = 'Configure';
-
-
-implementation
-
-{ TSurfacePreviewPlugin }
-
-procedure TSurfacePreviewPlugin.Configure;
-begin
- FSppConfigure;
-end;
-
-constructor TSurfacePreviewPlugin.Create(ModuleName: String);
-begin
- FModuleName := ModuleName;
- FHandle := LoadLibrary(PChar(FModuleName));
- if FHandle = 0 then
- raise ESppException.CreateFmt('Error loading %s', [FModuleName])
- else
- begin
- InitProcs;
- Load;
- end;
-end;
-
-destructor TSurfacePreviewPlugin.Destroy;
-begin
- FSppUnload;
- if not FreeLibrary(FHandle) then
- raise ESppException.CreateFmt('Error unloading %s', [FModuleName]);
- inherited;
-end;
-
-function TSurfacePreviewPlugin.GetImage(const Ghost: String;
- const Surface: integer; Bitmap: TBitmap): boolean;
-var H: HBITMAP;
-begin
- H := Bitmap.ReleaseHandle;
- Result := FSppGetImage(PChar(Ghost), Surface, H) = 0;
- Bitmap.Handle := H;
-end;
-
-function TSurfacePreviewPlugin.GetImageSize(const Ghost: String;
- const Surface: integer; var Width, Height: integer): boolean;
-begin
- Width := 0;
- Height := 0;
- // 0\82È\82ç\90³\8fí\8fI\97¹
- Result := FSppGetImageSize(PChar(Ghost), Surface, Width, Height) = 0;
-end;
-
-procedure TSurfacePreviewPlugin.InitProcs;
-var DLLName: array [0..255] of char;
-begin
- FSppGetVersion := GetProcAddress(FHandle, SSppGetVersion);
- if (@FSppGetVersion = nil) then
- raise ESppException.CreateFmt('%s is not a valid SPP module', [FModuleName]);
-
- FSppGetVersion(@DLLName, sizeof(DLLName), FVersion, FCanConfigure);
- if FVersion <> 1 then
- raise ESppException.CreateFmt('Module %s returned '+
- 'unsupported version number', [FModuleName]);
- FDLLName := DLLName;
-
- // Load other procedures
- FSppLoad := GetProcAddress(FHandle, SSppLoad);
- FSppUnload := GetProcAddress(FHandle, SSppUnload);
- FSppGetImage := GetProcAddress(FHandle, SSppGetImage);
- FSppGetImageSize := GetProcAddress(FHandle, SSppGetImageSize);
- FSppConfigure := GetProcAddress(FHandle, SSppConfigure);
-
- if (@FSppLoad = nil) or (@FSppUnload = nil) or (@FSppGetImage = nil) or
- (@FSppGetImageSize = nil) or (@FSppConfigure = nil) then
- begin
- raise ESppException.Create('Error Getting Procedure Address');
- end;
-end;
-
-procedure TSurfacePreviewPlugin.Load;
-begin
- FSppLoad(PChar(ExtractFilePath(FModuleName)));
-end;
-
-function TSurfacePreviewPlugin.SetSizeAndGetImage(const Ghost: String;
- const Surface: integer; Bitmap: TBitmap): boolean;
-var Width, Height: integer;
-begin
- Width := 0;
- Height := 0;
- Result := false;
- if Surface < 0 then Exit;
- if not GetImageSize(Ghost, Surface, Width, Height) then
- Exit;
- Bitmap.Width := Width;
- Bitmap.Height := Height;
- Result := GetImage(Ghost, Surface, Bitmap);
-end;
-
-end.