Skip to content

Commit 63b7b84

Browse files
committed
various bugfixes
1 parent 5365a0d commit 63b7b84

File tree

3 files changed

+52
-51
lines changed

3 files changed

+52
-51
lines changed

dll_binary/SvgShellExtensions.dll

0 Bytes
Binary file not shown.

source/SvgPreview.pas

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ interface
2626

2727
const
2828
extension = '.svg';
29-
appId = 'SVGShellExtensions';
30-
appDescription = 'SVG Shell Extensions';
31-
SID_EXT_ShellExtensions = '{B2980224-58B3-478C-B596-7D2B23F2C041}';
32-
IID_EXT_ShellExtensions: TGUID = SID_EXT_ShellExtensions;
29+
extFile = 'svgFile';
30+
appId = 'SVGShellHandler';
31+
appDescription = 'SVG Shell Handler';
3332

33+
SID_SVG_ShellHandler = '{B2980224-58B3-478C-B596-7D2B23F2C041}';
34+
IID_SVG_ShellHandler: TGUID = SID_SVG_ShellHandler;
3435
SID_IThumbnailProvider = '{E357FCCD-A995-4576-B01F-234630154E96}';
3536
IID_IThumbnailProvider: TGUID = SID_IThumbnailProvider;
3637

3738
darkBkColor = $202020;
3839
type
3940
TWTS_ALPHATYPE = (WTSAT_UNKNOWN, WTSAT_RGB, WTSAT_ARGB);
41+
4042
IThumbnailProvider = interface(IUnknown)
4143
[SID_IThumbnailProvider]
4244
function GetThumbnail(cx: Cardinal; out hbmp: HBITMAP;
@@ -314,15 +316,6 @@ function TSvgShellExt.Unload: HRESULT;
314316
end;
315317
//------------------------------------------------------------------------------
316318

317-
function TSvgShellExt.IInitializeWithStream_Init(const pstream: IStream;
318-
grfMode: DWORD): HRESULT;
319-
begin
320-
fStream := nil;
321-
fStream := pstream;
322-
result := S_OK;
323-
end;
324-
//------------------------------------------------------------------------------
325-
326319
function TSvgShellExt.GetThumbnail(cx: Cardinal;
327320
out hbmp: HBITMAP; out at: TWTS_ALPHATYPE): HRESULT;
328321
var
@@ -366,6 +359,15 @@ function TSvgShellExt.GetThumbnail(cx: Cardinal;
366359
img.Free;
367360
end;
368361
end;
362+
//------------------------------------------------------------------------------
363+
364+
function TSvgShellExt.IInitializeWithStream_Init(const pstream: IStream;
365+
grfMode: DWORD): HRESULT;
366+
begin
367+
fStream := nil;
368+
fStream := pstream;
369+
result := S_OK;
370+
end;
369371

370372
//------------------------------------------------------------------------------
371373
//------------------------------------------------------------------------------
@@ -387,8 +389,8 @@ initialization
387389

388390
LoadFonts; //needed when displaying SVG text
389391
TComObjectFactory.Create(ComServer,
390-
TSvgShellExt, IID_EXT_ShellExtensions,
391-
appId, appDescription, ciMultiInstance, tmApartment);
392+
TSvgShellExt, IID_SVG_ShellHandler,
393+
extFile, appDescription, ciMultiInstance, tmApartment);
392394

393395
finalization
394396
if res = S_OK then OleUninitialize();

source/SvgShellExtensions.dpr

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ library SvgShellExtensions;
33
(*******************************************************************************
44
* Author : Angus Johnson *
55
* Version : 1.1 *
6-
* Date : 21 January 2022 *
6+
* Date : 14 October 2023 *
77
* Website : http://www.angusj.com *
8-
* Copyright : Angus Johnson 2022 *
8+
* Copyright : Angus Johnson 2022-2023 *
99
* *
1010
* Purpose : 64bit Windows Explorer Preview Handler for QOI image files *
1111
* *
@@ -27,7 +27,9 @@ uses
2727
{$R *.res}
2828

2929
const
30-
sSurrogateAppId = '{6D2B5079-2F0B-48DD-AB7F-97CEC514D30B}'; //64bit
30+
// Preview Handler Surrogate Host (Prevhost.exe)
31+
// see HKEY_CLASSES_ROOT\AppID
32+
sSurrogateAppId = '{6D2B5079-2F0B-48DD-AB7F-97CEC514D30B}';
3133

3234
function GetModuleName: string;
3335
var
@@ -45,62 +47,56 @@ var
4547
reg: TRegistry;
4648
begin
4749
Result := E_UNEXPECTED; //will fail if not ADMIN
48-
4950
reg := TRegistry.Create(KEY_ALL_ACCESS);
5051
try
5152
reg.RootKey := HKEY_CLASSES_ROOT;
5253
if not reg.OpenKey(extension, true) then Exit;
53-
reg.WriteString('', appId);
54+
reg.WriteString('', extFile); //'svgFile' (see SvgPreview.pas)
5455
reg.CloseKey;
55-
56-
if reg.OpenKey(appId+'\Clsid', true) then
57-
begin
58-
reg.WriteString('', SID_EXT_ShellExtensions);
59-
reg.CloseKey;
60-
end;
61-
62-
//REGISTER PREVIEW HANDLER
63-
if not reg.OpenKey(appId+'\ShellEx\'+SID_IPreviewHandler, true) then Exit;
64-
reg.WriteString('', SID_EXT_ShellExtensions);
56+
if not reg.OpenKey(extFile, true) then Exit;
6557
reg.CloseKey;
66-
//REGISTER THUMBNAIL PROVIDER
67-
if not reg.OpenKey(appId+'\ShellEx\'+SID_IThumbnailProvider, true) then Exit;
68-
reg.WriteString('', SID_EXT_ShellExtensions);
58+
59+
if not reg.OpenKey(extFile+'\CLSID', true) then Exit;
60+
reg.WriteString('', SID_SVG_ShellHandler);
6961
reg.CloseKey;
7062

71-
////////////////////////////////////////////////////////////////////////////
72-
//the following also seems necessary (at least for SVG files)
63+
//REGISTER PREVIEW HANDLER and THUMBNAIL PROVIDER (under .svg)
7364
if not reg.OpenKey(extension+'\ShellEx\'+SID_IPreviewHandler, true) then Exit;
74-
reg.WriteString('', SID_EXT_ShellExtensions);
65+
reg.WriteString('', SID_SVG_ShellHandler);
7566
reg.CloseKey;
7667
if not reg.OpenKey(extension+'\ShellEx\'+SID_IThumbnailProvider, true) then Exit;
77-
reg.WriteString('', SID_EXT_ShellExtensions);
68+
reg.WriteString('', SID_SVG_ShellHandler);
7869
reg.CloseKey;
79-
////////////////////////////////////////////////////////////////////////////
8070

81-
if not reg.OpenKey('CLSID\'+ SID_EXT_ShellExtensions, true) then Exit;
71+
//REGISTER PREVIEW HANDLER and THUMBNAIL PROVIDER (under .svgFile)
72+
if not reg.OpenKey(extFile +'\ShellEx\'+SID_IPreviewHandler, true) then Exit;
73+
reg.WriteString('', SID_SVG_ShellHandler);
74+
reg.CloseKey;
75+
if not reg.OpenKey(extFile +'\ShellEx\'+SID_IThumbnailProvider, true) then Exit;
76+
reg.WriteString('', SID_SVG_ShellHandler);
77+
reg.CloseKey;
78+
79+
if not reg.OpenKey('CLSID\'+ SID_SVG_ShellHandler, true) then Exit;
8280
reg.WriteString('', appDescription);
8381
reg.WriteString('AppID', sSurrogateAppId);
8482
reg.CloseKey;
8583

86-
reg.OpenKey('CLSID\'+ SID_EXT_ShellExtensions+'\InProcServer32', true);
84+
reg.OpenKey('CLSID\'+ SID_SVG_ShellHandler+'\InProcServer32', true);
8785
reg.WriteString('', GetModuleName);
8886
reg.WriteString('ThreadingModel', 'Apartment');
89-
reg.WriteString('ProgId', appId);
90-
reg.WriteString('VersionIndependentProgID', appId);
9187
reg.CloseKey;
9288

93-
reg.OpenKey('CLSID\' + SID_EXT_ShellExtensions + '\ProgId', true);
94-
reg.WriteString('', appId);
89+
reg.OpenKey('CLSID\' + SID_SVG_ShellHandler + '\ProgId', true);
90+
reg.WriteString('', extFile);
9591
reg.CloseKey;
9692

9793
reg.RootKey := HKEY_LOCAL_MACHINE;
98-
if reg.OpenKey('SOFTWARE\Microsoft\Windows\'+
99-
'CurrentVersion\PreviewHandlers', true) then
94+
if reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\PreviewHandlers', true) then
10095
begin
101-
reg.WriteString(SID_EXT_ShellExtensions, appDescription);
96+
reg.WriteString(SID_SVG_ShellHandler, appDescription);
10297
reg.CloseKey;
10398
end;
99+
104100
finally
105101
reg.Free;
106102
end;
@@ -121,17 +117,20 @@ begin
121117
reg.RootKey := HKEY_LOCAL_MACHINE;
122118
if reg.OpenKey('SOFTWARE\Microsoft\Windows\'+
123119
'CurrentVersion\PreviewHandlers', true) and
124-
reg.ValueExists(SID_EXT_ShellExtensions) then
125-
reg.DeleteValue(SID_EXT_ShellExtensions);
120+
reg.ValueExists(SID_SVG_ShellHandler) then
121+
reg.DeleteValue(SID_SVG_ShellHandler);
126122

127123
reg.RootKey := HKEY_CLASSES_ROOT;
128124
if reg.KeyExists(extension + '\ShellEx\'+SID_IPreviewHandler) then
129125
reg.DeleteKey(extension + '\ShellEx\'+SID_IPreviewHandler);
130126
if reg.KeyExists(extension + '\ShellEx\'+SID_IThumbnailProvider) then
131127
reg.DeleteKey(extension + '\ShellEx\'+SID_IThumbnailProvider);
132128

133-
reg.DeleteKey('CLSID\'+SID_EXT_ShellExtensions);
134-
reg.DeleteKey(appId);
129+
reg.DeleteKey('CLSID\'+SID_SVG_ShellHandler);
130+
reg.DeleteKey(extFile+'\ShellEx\'+SID_IPreviewHandler);
131+
reg.DeleteKey(extFile+'\ShellEx\'+SID_IThumbnailProvider);
132+
reg.DeleteKey(extFile+'\Clsid');
133+
135134
finally
136135
reg.Free;
137136
end;

0 commit comments

Comments
 (0)