1010// / @parblock
1111// /
1212// / Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
13- // / Copyright 1991-2018 Persistence of Vision Raytracer Pty. Ltd.
13+ // / Copyright 1991-2021 Persistence of Vision Raytracer Pty. Ltd.
1414// /
1515// / POV-Ray is free software: you can redistribute it and/or modify
1616// / it under the terms of the GNU Affero General Public License as
4242#include < shellapi.h>
4343#include < cstring>
4444#include < sys/stat.h>
45+ #include < delayimp.h>
4546#include " pvengine.h"
4647#include " pvedit.h"
4748#include " parser/reservedwords.h"
@@ -162,6 +163,37 @@ char *FunctionNames [] =
162163 NULL
163164 } ;
164165
166+ void EditorDLLNotFoundPopup (const char * function, long err)
167+ {
168+ char str[2048 ];
169+ #ifdef _DEBUG
170+ sprintf (str,
171+ " Editor DLL initialisation failed [%s failed, code is %08lx]\n\n "
172+ " Debug build: if you have renamed cmedit as cmeditd, keep in mind that it "
173+ " will still look for povcmax.dll, not povcmaxd.dll. Also, for debug builds "
174+ " the build output directory is checked for the DLL's before the install dir.\n\n "
175+ " Check the README in the source for instructions on how to copy the DLL's from "
176+ " the official distribution to the naming convention used by debug builds." ,
177+ function, err);
178+ PovMessageBox (str, " POV-Ray Editor error" );
179+ PovMessageBox (" See the 'Internal Editor Reference' section in the help file for\n "
180+ " instructions on how to correct this or turn editor loading off." , " Important!" );
181+ #else
182+ if (MessageBox (main_window,
183+ " POV-Ray could not load its internal editor. This is to be expected "
184+ " if you installed the AGPL-licensed distribution, as the editor DLL "
185+ " is not included. If you do not wish to use the editor you can turn "
186+ " it off (and stop this message appearing) by unchecking 'Use Editor' "
187+ " under the 'Other Settings' sub-menu of the Options menu.\n\n "
188+ " If you wish to enable the editor, clicking 'Yes' below will take "
189+ " you to its download page." ,
190+ " Could not load internal editor - download it?" ,
191+ MB_ICONQUESTION | MB_YESNO) == IDYES)
192+ ShellExecute (NULL , NULL , " http://www.povray.org/download/wineditdll/" POV_RAY_VERSION,
193+ NULL , NULL , SW_SHOWNORMAL);
194+ #endif
195+ }
196+
165197bool LoadEditorDLL (char *path, bool errorOK)
166198{
167199 int DllVersion ;
@@ -171,7 +203,7 @@ bool LoadEditorDLL (char *path, bool errorOK)
171203 void ***f ;
172204 struct stat statbuf ;
173205
174- if (!editors_enabled)
206+ if (!editors_enabled)
175207 return (false ) ;
176208 if (debugging)
177209 debug_output (" Trying to load editor DLL from '%s' [%s]\n " , path, stat (path, &statbuf) != 0 ? " missing" : " found" ) ;
@@ -181,36 +213,9 @@ bool LoadEditorDLL (char *path, bool errorOK)
181213 {
182214 err = GetLastError () ;
183215 if (debugging)
184- debug_output (" Could not load editor DLL '%s', error code is %08lx \n " , path, err) ;
216+ debug_output (" Could not load editor DLL '%s', error code is %08x \n " , path, err) ;
185217 if (!errorOK)
186- {
187- #ifdef _DEBUG
188- sprintf (str,
189- " Editor DLL initialisation failed [LoadLibrary failed, code is %08lx]\n\n "
190- " Debug build: if you have renamed cmedit as cmeditd, keep in mind that it "
191- " will still look for povcmax.dll, not povcmaxd.dll. Also, for debug builds "
192- " the build output directory is checked for the DLL's before the install dir.\n\n "
193- " Check the README in the source for instructions on how to copy the DLL's from "
194- " the official distribution to the naming convention used by debug builds." ,
195- err) ;
196- PovMessageBox (str, " POV-Ray Editor error" ) ;
197- PovMessageBox (" See the 'Internal Editor Reference' section in the help file for\n "
198- " instructions on how to correct this or turn editor loading off." , " Important!" ) ;
199- #else
200- if (MessageBox (main_window,
201- " POV-Ray could not load its internal editor. This is to be expected "
202- " if you installed the AGPL-licensed distribution, as the editor DLL "
203- " is not included. If you do not wish to use the editor you can turn "
204- " it off (and stop this message appearing) by unchecking 'Use Editor' "
205- " under the 'Other Settings' sub-menu of the Options menu.\n\n "
206- " If you wish to enable the editor, clicking 'Yes' below will take "
207- " you to its download page." ,
208- " Could not load internal editor - download it?" ,
209- MB_ICONQUESTION | MB_YESNO) == IDYES)
210- ShellExecute (NULL , NULL , " http://www.povray.org/download/wineditdll/" POV_RAY_VERSION,
211- NULL , NULL , SW_SHOWNORMAL) ;
212- #endif
213- }
218+ EditorDLLNotFoundPopup (" LoadLibraryEx" , err);
214219 return (false ) ;
215220 }
216221
@@ -337,22 +342,32 @@ HWND InitialiseEditor (HWND ParentWindow, HWND StatusWindow, const char *Binarie
337342{
338343 HWND hwnd ;
339344
340- if (!editors_enabled || !use_editors)
345+ __try // First call to the delay-loaded editor DLL might fail spectacularly if the DLL can't be found.
346+ {
347+ if (!editors_enabled || !use_editors)
341348 return (NULL ) ;
342349
343- char *s1 = Get_User_Keywords (DocumentsPath);
344- char *s2 = Get_Reserved_Words (s1) ;
345- char *s3 = Get_INI_Keywords () ;
346- EditSetKeywords (s2, s3) ;
347- free (s1) ;
348- free (s2);
349- free (s3);
350- if ((hwnd = CreateTabWindow (ParentWindow, StatusWindow, BinariesPath, DocumentsPath)) == NULL )
350+ char *s1 = Get_User_Keywords (DocumentsPath);
351+ char *s2 = Get_Reserved_Words (s1) ;
352+ char *s3 = Get_INI_Keywords () ;
353+ EditSetKeywords (s2, s3) ;
354+ free (s1) ;
355+ free (s2);
356+ free (s3);
357+ if ((hwnd = CreateTabWindow (ParentWindow, StatusWindow, BinariesPath, DocumentsPath)) == NULL )
358+ {
359+ PovMessageBox (" TabWindow error: see the 'Built-In Editors' section in the help file" , " Important!" ) ;
360+ return (NULL ) ;
361+ }
362+ return (hwnd) ;
363+ }
364+ __except (GetExceptionCode () == VcppException (ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND))
351365 {
352- PovMessageBox (" TabWindow error: see the 'Built-In Editors' section in the help file" , " Important!" ) ;
353- return (NULL ) ;
366+ if (debugging)
367+ debug_output (" Could not delayed-link editor DLL\n " );
368+ EditorDLLNotFoundPopup (" delayed linkage" , GetExceptionCode ());
369+ return (NULL );
354370 }
355- return (hwnd) ;
356371}
357372
358373void SetEditorPosition (int x, int y, int w, int h)
0 commit comments