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
112
113
114
|
unit ImgDecoder;
interface
uses Windows;
function IsImgDecoderAvailable:boolean;
function ImgNewDecoder(var pDecoder:pointer):dword;
function ImgDeleteDecoder(pDecoder:pointer):dword;
function ImgNewDIBFromFile(pDecoder:pointer;Filename:PAnsiChar;var pImg:pointer):dword;
function ImgDeleteDIBSection(pImg:pointer):dword;
function ImgGetHandle(pImg:pointer;var pBitmap:HBITMAP;var ppDIBBits:pointer):dword;
implementation
const
hModule:THANDLE=0;
type
tImgNewDecoder =function(var pDecoder:pointer):dword; stdcall;
tImgDeleteDecoder =function(pDecoder:pointer):dword; stdcall;
tImgNewDIBFromFile =function(pDecoder:pointer;Filename:PAnsiChar;var pImg):dword; stdcall;
tImgDeleteDIBSection=function(pImg:pointer):dword; stdcall;
tImgGetHandle =function(pImg:pointer;var pBitmap:HBITMAP;var ppDIBBits:pointer):dword; stdcall;
const
pImgNewDecoder :tImgNewDecoder = nil;
pImgDeleteDecoder :tImgDeleteDecoder = nil;
pImgNewDIBFromFile :tImgNewDIBFromFile = nil;
pImgDeleteDIBSection:tImgDeleteDIBSection = nil;
pImgGetHandle :tImgGetHandle = nil;
function IsImgDecoderAvailable:boolean;
begin
result:=hModule<>0;
end;
function ImgNewDecoder(var pDecoder:pointer):dword;
begin
if @pImgNewDecoder<>nil then
result:=pImgNewDecoder(pDecoder)
else
result:=0;
end;
function ImgDeleteDecoder(pDecoder:pointer):dword;
begin
if @pImgDeleteDecoder<>nil then
result:=pImgDeleteDecoder(pDecoder)
else
result:=0;
end;
function ImgNewDIBFromFile(pDecoder:pointer;Filename:PAnsiChar;var pImg:pointer):dword;
begin
if @pImgNewDecoder<>nil then
result:=pImgNewDIBFromFile(pDecoder,Filename,pImg)
else
result:=0;
end;
function ImgDeleteDIBSection(pImg:pointer):dword;
begin
if @pImgNewDecoder<>nil then
result:=pImgDeleteDIBSection(pImg)
else
result:=0;
end;
function ImgGetHandle(pImg:pointer;var pBitmap:HBITMAP;var ppDIBBits:pointer):dword;
begin
if @pImgGetHandle<>nil then
result:=pImgGetHandle(pImg,pBitmap,ppDIBBits)
else
result:=0;
end;
initialization
hModule:=LoadLibrary('imgdecoder.dll');
if hModule=0 then
hModule:=LoadLibrary('plugins\imgdecoder.dll');
if hModule<>0 then
begin
pImgNewDecoder :=GetProcAddress(hModule, 'ImgNewDecoder');
pImgDeleteDecoder :=GetProcAddress(hModule, 'ImgDeleteDecoder');
pImgNewDIBFromFile :=GetProcAddress(hModule, 'ImgNewDIBFromFile');
pImgDeleteDIBSection:=GetProcAddress(hModule, 'ImgDeleteDIBSection');
pImgGetHandle :=GetProcAddress(hModule, 'ImgGetHandle');
end;
finalization
if hModule<>0 then
FreeLibrary(hModule);
end.
{ Sample of using
var
pDecoder:pointer;
pImg:pointer;
bitmap:HBITMAP;
pBits:pointer;
begin
if IsImgDecoderAvailable then
begin
ImgNewDecoder(pDecoder);
if ImgNewDIBFromFile(pDecoder,PAnsiChar(ParamStr(1)),pImg)<>0 then
begin
ImgGetHandle(pImg,bitmap,pBits);
// action
ImgDeleteDIBSection(pImg);
end;
ImgDeleteDecoder(pDecoder);
end;
end.
}
|