2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Windows NT Utility Methods for MagickCore %
20 % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % https://imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 #include "MagickCore/studio.h"
42 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
43 #include "MagickCore/client.h"
44 #include "MagickCore/exception-private.h"
45 #include "MagickCore/locale_.h"
46 #include "MagickCore/log.h"
47 #include "MagickCore/magick.h"
48 #include "MagickCore/memory_.h"
49 #include "MagickCore/memory-private.h"
50 #include "MagickCore/nt-base.h"
51 #include "MagickCore/nt-base-private.h"
52 #include "MagickCore/resource_.h"
53 #include "MagickCore/resource-private.h"
54 #include "MagickCore/timer.h"
55 #include "MagickCore/string_.h"
56 #include "MagickCore/string-private.h"
57 #include "MagickCore/utility.h"
58 #include "MagickCore/utility-private.h"
59 #include "MagickCore/version.h"
60 #if defined(MAGICKCORE_LTDL_DELEGATE)
63 #if defined(MAGICKCORE_CIPHER_SUPPORT)
71 #if !defined(MAP_FAILED)
72 #define MAP_FAILED ((void *)(LONG_PTR)-1)
80 We need to make sure only one instance is created for each process and that
81 is why we wrap the new/delete instance methods.
83 From: http://www.ghostscript.com/doc/current/API.htm
84 "The Win32 DLL gsdll32.dll can be used by multiple programs simultaneously,
85 but only once within each process"
87 typedef struct _NTGhostInfo
90 (MagickDLLCall *delete_instance)(gs_main_instance *);
93 (MagickDLLCall *new_instance)(gs_main_instance **,void *);
102 #if !defined(MAGICKCORE_LTDL_DELEGATE)
104 *lt_slsearchpath = (char *) NULL;
114 *ghost_handle = (void *) NULL;
117 *ghost_semaphore = (SemaphoreInfo *) NULL,
118 *winsock_semaphore = (SemaphoreInfo *) NULL;
121 *wsaData = (WSADATA*) NULL;
131 const registry_roots[2] =
133 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
134 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
138 External declarations.
140 #if !defined(MAGICKCORE_WINDOWS_SUPPORT)
141 extern "C" BOOL WINAPI
142 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
145 static void MagickDLLCall NTGhostscriptDeleteInstance(
146 gs_main_instance *instance)
148 LockSemaphoreInfo(ghost_semaphore);
149 nt_ghost_info.delete_instance(instance);
150 nt_ghost_info.has_instance=MagickFalse;
151 UnlockSemaphoreInfo(ghost_semaphore);
154 static int MagickDLLCall NTGhostscriptNewInstance(gs_main_instance **pinstance,
160 LockSemaphoreInfo(ghost_semaphore);
162 if (nt_ghost_info.has_instance == MagickFalse)
164 status=nt_ghost_info.new_instance(pinstance,caller_handle);
166 nt_ghost_info.has_instance=MagickTrue;
168 UnlockSemaphoreInfo(ghost_semaphore);
172 static inline char *create_utf8_string(const wchar_t *wideChar)
180 count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,NULL,0,NULL,NULL);
182 return((char *) NULL);
183 utf8=(char *) AcquireQuantumMemory(count+1,sizeof(*utf8));
184 if (utf8 == (char *) NULL)
185 return((char *) NULL);
186 count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,utf8,count,NULL,NULL);
189 utf8=DestroyString(utf8);
190 return((char *) NULL);
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 % DllMain() is an entry point to the DLL which is called when processes and
208 % threads are initialized and terminated, or upon calls to the Windows
209 % LoadLibrary and FreeLibrary functions.
211 % The function returns TRUE of it succeeds, or FALSE if initialization fails.
213 % The format of the DllMain method is:
215 % BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
217 % A description of each parameter follows:
219 % o handle: handle to the DLL module
221 % o reason: reason for calling function:
223 % DLL_PROCESS_ATTACH - DLL is being loaded into virtual address
224 % space of current process.
225 % DLL_THREAD_ATTACH - Indicates that the current process is
226 % creating a new thread. Called under the
227 % context of the new thread.
228 % DLL_THREAD_DETACH - Indicates that the thread is exiting.
229 % Called under the context of the exiting
231 % DLL_PROCESS_DETACH - Indicates that the DLL is being unloaded
232 % from the virtual address space of the
235 % o lpvReserved: Used for passing additional info during DLL_PROCESS_ATTACH
236 % and DLL_PROCESS_DETACH.
239 #if defined(_DLL) && defined(ProvideDllMain)
240 BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
244 case DLL_PROCESS_ATTACH:
255 MagickCoreGenesis((const char *) NULL,MagickFalse);
256 wide_path=(wchar_t *) AcquireQuantumMemory(MagickPathExtent,
258 if (wide_path == (wchar_t *) NULL)
260 count=(ssize_t) GetModuleFileNameW(handle,wide_path,MagickPathExtent);
266 module_path=create_utf8_string(wide_path);
267 for ( ; count > 0; count--)
268 if (module_path[count] == '\\')
270 module_path[count+1]='\0';
273 path=(char *) AcquireQuantumMemory(16UL*MagickPathExtent,sizeof(*path));
274 if (path == (char *) NULL)
276 module_path=DestroyString(module_path);
277 wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
280 count=(ssize_t) GetEnvironmentVariable("PATH",path,16*MagickPathExtent);
281 if ((count != 0) && (strstr(path,module_path) == (char *) NULL))
283 if ((strlen(module_path)+count+1) < (16*MagickPathExtent-1))
288 variable=(char *) AcquireQuantumMemory(16UL*MagickPathExtent,
290 if (variable == (char *) NULL)
292 path=DestroyString(path);
293 module_path=DestroyString(module_path);
294 wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
297 (void) FormatLocaleString(variable,16*MagickPathExtent,
298 "%s;%s",module_path,path);
299 SetEnvironmentVariable("PATH",variable);
300 variable=DestroyString(variable);
303 path=DestroyString(path);
304 module_path=DestroyString(module_path);
306 wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
309 case DLL_PROCESS_DETACH:
311 MagickCoreTerminus();
322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % Exit() calls TerminateProcess for Win95.
334 % The format of the exit method is:
336 % int Exit(int status)
338 % A description of each parameter follows:
340 % o status: an integer value representing the status of the terminating
344 MagickPrivate int Exit(int status)
348 TerminateProcess(GetCurrentProcess(),(unsigned int) status);
354 #if !defined(__MINGW32__)
356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360 % g e t t i m e o f d a y %
364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366 % The gettimeofday() method get the time of day.
368 % The format of the gettimeofday method is:
370 % int gettimeofday(struct timeval *time_value,struct timezone *time_zone)
372 % A description of each parameter follows:
374 % o time_value: the time value.
376 % o time_zone: the time zone.
379 MagickPrivate int gettimeofday (struct timeval *time_value,
380 struct timezone *time_zone)
382 #define EpochFiletime MagickLLConstant(116444736000000000)
387 if (time_value != (struct timeval *) NULL)
398 GetSystemTimeAsFileTime(&file_time);
399 date_time.LowPart=file_time.dwLowDateTime;
400 date_time.HighPart=file_time.dwHighDateTime;
401 time=date_time.QuadPart;
404 time_value->tv_sec=(ssize_t) (time / 1000000);
405 time_value->tv_usec=(ssize_t) (time % 1000000);
407 if (time_zone != (struct timezone *) NULL)
414 time_zone->tz_minuteswest=_timezone/60;
415 time_zone->tz_dsttime=_daylight;
422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 % I s W i n d o w s 9 5 %
430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
432 % IsWindows95() returns true if the system is Windows 95.
434 % The format of the IsWindows95 method is:
439 MagickPrivate int IsWindows95()
444 version_info.dwOSVersionInfoSize=sizeof(version_info);
445 if (GetVersionEx(&version_info) &&
446 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456 % N T A r g v T o U T F 8 %
460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 % NTArgvToUTF8() converts the wide command line arguments to UTF-8 to ensure
463 % compatibility with Linux.
465 % The format of the NTArgvToUTF8 method is:
467 % char **NTArgvToUTF8(const int argc,wchar_t **argv)
469 % A description of each parameter follows:
471 % o argc: the number of command line arguments.
473 % o argv: the wide-character command line arguments.
476 MagickPrivate char **NTArgvToUTF8(const int argc,wchar_t **argv)
484 utf8=(char **) AcquireQuantumMemory(argc,sizeof(*utf8));
485 if (utf8 == (char **) NULL)
486 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
487 for (i=0; i < (ssize_t) argc; i++)
489 utf8[i]=create_utf8_string(argv[i]);
490 if (utf8[i] == (char *) NULL)
492 for (i--; i >= 0; i--)
493 utf8[i]=DestroyString(utf8[i]);
494 ThrowFatalException(ResourceLimitFatalError,
495 "UnableToConvertStringToARGV");
502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506 % N T C l o s e D i r e c t o r y %
510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512 % NTCloseDirectory() closes the named directory stream and frees the DIR
515 % The format of the NTCloseDirectory method is:
517 % int NTCloseDirectory(DIR *entry)
519 % A description of each parameter follows:
521 % o entry: Specifies a pointer to a DIR structure.
524 MagickPrivate int NTCloseDirectory(DIR *entry)
526 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
527 assert(entry != (DIR *) NULL);
528 FindClose(entry->hSearch);
529 entry=(DIR *) RelinquishMagickMemory(entry);
533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
537 % N T C l o s e L i b r a r y %
541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
543 % NTCloseLibrary() unloads the module associated with the passed handle.
545 % The format of the NTCloseLibrary method is:
547 % void NTCloseLibrary(void *handle)
549 % A description of each parameter follows:
551 % o handle: Specifies a handle to a previously loaded dynamic module.
554 MagickPrivate int NTCloseLibrary(void *handle)
557 return(FreeLibrary((HINSTANCE) handle));
558 return(!(FreeLibrary((HINSTANCE) handle)));
562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
566 % N T C o n t r o l H a n d l e r %
570 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
572 % NTControlHandler() registers a control handler that is activated when, for
573 % example, a ctrl-c is received.
575 % The format of the NTControlHandler method is:
577 % int NTControlHandler(void)
581 static BOOL ControlHandler(DWORD type)
584 AsynchronousResourceComponentTerminus();
588 MagickPrivate int NTControlHandler(void)
590 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598 % N T E l a p s e d T i m e %
602 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
604 % NTElapsedTime() returns the elapsed time (in seconds) since the last call to
607 % The format of the ElapsedTime method is:
609 % double NTElapsedTime(void)
612 MagickPrivate double NTElapsedTime(void)
626 GetSystemTime(&system_time);
627 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
628 return((double) 1.0e-7*elapsed_time.filetime64);
632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
642 % NTErf() computes the error function of x.
644 % The format of the NTErf method is:
646 % double NTCloseDirectory(DIR *entry)
648 % A description of each parameter follows:
650 % o x: Specifies a pointer to a DIR structure.
653 MagickPrivate double NTErf(double x)
679 y=1.0-(((((a5*t+a4)*t)+a3)*t+a2)*t+a1)*t*exp(-x*x);
685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689 + N T E r r o r H a n d l e r %
693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
695 % NTErrorHandler() displays an error reason and then terminates the program.
697 % The format of the NTErrorHandler method is:
699 % void NTErrorHandler(const ExceptionType severity,const char *reason,
700 % const char *description)
702 % A description of each parameter follows:
704 % o severity: Specifies the numeric error category.
706 % o reason: Specifies the reason to display before terminating the
709 % o description: Specifies any description to the reason.
712 MagickPrivate void NTErrorHandler(const ExceptionType severity,
713 const char *reason,const char *description)
716 buffer[3*MagickPathExtent],
720 if (reason == (char *) NULL)
722 MagickCoreTerminus();
725 message=GetExceptionMessage(errno);
726 if ((description != (char *) NULL) && errno)
727 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s (%s) [%s].\n",
728 GetClientName(),reason,description,message);
730 if (description != (char *) NULL)
731 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s (%s).\n",
732 GetClientName(),reason,description);
735 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s [%s].\n",
736 GetClientName(),reason,message);
738 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s.\n",
739 GetClientName(),reason);
740 message=DestroyString(message);
741 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
742 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
743 MagickCoreTerminus();
748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
752 % N T E x i t L i b r a r y %
756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
758 % NTExitLibrary() exits the dynamic module loading subsystem.
760 % The format of the NTExitLibrary method is:
762 % int NTExitLibrary(void)
765 MagickPrivate int NTExitLibrary(void)
771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775 % N T G a t h e r R a n d o m D a t a %
779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
781 % NTGatherRandomData() gathers random data and returns it.
783 % The format of the GatherRandomData method is:
785 % MagickBooleanType NTGatherRandomData(const size_t length,
786 % unsigned char *random)
788 % A description of each parameter follows:
790 % length: the length of random data buffer
792 % random: the random data is returned here.
795 MagickPrivate MagickBooleanType NTGatherRandomData(const size_t length,
796 unsigned char *random)
798 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
805 handle=(HCRYPTPROV) NULL;
806 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
807 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
809 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
810 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
813 status=CryptGenRandom(handle,(DWORD) length,random);
816 status=CryptReleaseContext(handle,0);
819 status=CryptReleaseContext(handle,0);
830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
834 % N T G e t E x e c u t i o n P a t h %
838 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
840 % NTGetExecutionPath() returns the execution path of a program.
842 % The format of the GetExecutionPath method is:
844 % MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
846 % A description of each parameter follows:
848 % o path: the pathname of the executable that started the process.
850 % o extent: the maximum extent of the path.
853 MagickPrivate MagickBooleanType NTGetExecutionPath(char *path,
857 wide_path[MagickPathExtent];
859 (void) GetModuleFileNameW((HMODULE) NULL,wide_path,(DWORD) extent);
860 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(int) extent,NULL,
866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
870 % N T G e t L a s t E r r o r %
874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
876 % NTGetLastError() returns the last error that occurred.
878 % The format of the NTGetLastError method is:
880 % char *NTGetLastError(void)
883 char *NTGetLastError(void)
894 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
895 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
896 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
898 reason=AcquireString("An unknown error occurred");
901 reason=AcquireString((const char *) buffer);
908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912 % N T G e t L i b r a r y E r r o r %
916 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
918 % Lt_dlerror() returns a pointer to a string describing the last error
919 % associated with a lt_dl method. Note that this function is not thread
920 % safe so it should only be used under the protection of a lock.
922 % The format of the NTGetLibraryError method is:
924 % const char *NTGetLibraryError(void)
927 MagickPrivate const char *NTGetLibraryError(void)
930 last_error[MagickPathExtent];
936 error=NTGetLastError();
938 (void) CopyMagickString(last_error,error,MagickPathExtent);
939 error=DestroyString(error);
944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
948 % N T G e t L i b r a r y S y m b o l %
952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
954 % NTGetLibrarySymbol() retrieve the procedure address of the method
955 % specified by the passed character string.
957 % The format of the NTGetLibrarySymbol method is:
959 % void *NTGetLibrarySymbol(void *handle,const char *name)
961 % A description of each parameter follows:
963 % o handle: Specifies a handle to the previously loaded dynamic module.
965 % o name: Specifies the procedure entry point to be returned.
968 void *NTGetLibrarySymbol(void *handle,const char *name)
973 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
975 return((void *) NULL);
976 return((void *) lpfnDllFunc1);
980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
984 % N T G e t M o d u l e P a t h %
988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
990 % NTGetModulePath() returns the path of the specified module.
992 % The format of the GetModulePath method is:
994 % MagickBooleanType NTGetModulePath(const char *module,char *path)
996 % A description of each parameter follows:
998 % modith: the module name.
1000 % path: the module path is returned here.
1003 MagickPrivate MagickBooleanType NTGetModulePath(const char *module,char *path)
1006 module_path[MagickPathExtent];
1015 handle=GetModuleHandle(module);
1016 if (handle == (HMODULE) NULL)
1017 return(MagickFalse);
1018 length=GetModuleFileName(handle,module_path,MagickPathExtent);
1020 GetPathComponent(module_path,HeadPath,path);
1025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1029 + N T G e t P a g e S i z e %
1033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1035 % NTGetPageSize() returns the memory page size under Windows.
1037 % The format of the NTPageSize
1042 MagickPrivate ssize_t NTGetPageSize(void)
1047 GetSystemInfo(&system_info);
1048 return((ssize_t) system_info.dwPageSize);
1052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1056 % N T G h o s t s c r i p t D L L %
1060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1062 % NTGhostscriptDLL() returns the path to the most recent Ghostscript version
1063 % DLL. The method returns TRUE on success otherwise FALSE.
1065 % The format of the NTGhostscriptDLL method is:
1067 % int NTGhostscriptDLL(char *path,int length)
1069 % A description of each parameter follows:
1071 % o path: return the Ghostscript DLL path here.
1073 % o length: the buffer length.
1077 static int NTGetRegistryValue(HKEY root,const char *key,DWORD flags,
1078 const char *name,char *value,int *length)
1095 Get a registry value: key = root\\key, named value = name.
1097 if (RegOpenKeyExA(root,key,0,KEY_READ | flags,&hkey) != ERROR_SUCCESS)
1098 return(1); /* no match */
1102 if (p == (BYTE *) NULL)
1103 p=(&byte); /* ERROR_MORE_DATA only if value is NULL */
1104 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
1106 if (status == ERROR_SUCCESS)
1109 return(0); /* return the match */
1111 if (status == ERROR_MORE_DATA)
1114 return(-1); /* buffer not large enough */
1116 return(1); /* not found */
1119 static int NTLocateGhostscript(DWORD flags,int *root_index,
1120 const char **product_family,int *major_version,int *minor_version)
1134 "Aladdin Ghostscript"
1138 Find the most recent version of Ghostscript.
1142 *product_family=NULL;
1144 *minor_version=49; /* min version of Ghostscript is 5.50 */
1145 for (i=0; i < (ssize_t) (sizeof(products)/sizeof(products[0])); i++)
1148 key[MagickPathExtent];
1159 (void) FormatLocaleString(key,MagickPathExtent,"SOFTWARE\\%s",products[i]);
1160 for (j=0; j < (ssize_t) (sizeof(registry_roots)/sizeof(registry_roots[0]));
1163 mode=KEY_READ | flags;
1164 if (RegOpenKeyExA(registry_roots[j].hkey,key,0,mode,&hkey) ==
1174 Now enumerate the keys.
1176 extent=sizeof(key)/sizeof(char);
1177 for (k=0; RegEnumKeyA(hkey,k,key,extent) == ERROR_SUCCESS; k++)
1185 if (sscanf(key,"%d.%d",&major,&minor) != 2)
1187 if ((major > *major_version) || ((major == *major_version) &&
1188 (minor > *minor_version)))
1191 *product_family=products[i];
1192 *major_version=major;
1193 *minor_version=minor;
1197 (void) RegCloseKey(hkey);
1201 if (status == MagickFalse)
1206 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
1207 "version %d.%02d",*product_family,*major_version,*minor_version);
1211 static int NTGhostscriptGetString(const char *name,BOOL *is_64_bit,
1212 char *value,const size_t length)
1215 buffer[MagickPathExtent],
1222 *product_family=(const char *) NULL;
1225 is_64_bit_version=FALSE;
1234 Get a string from the installed Ghostscript.
1237 directory=(char *) NULL;
1238 if (LocaleCompare(name,"GS_DLL") == 0)
1240 directory=GetEnvironmentValue("MAGICK_GHOSTSCRIPT_PATH");
1241 if (directory != (char *) NULL)
1243 (void) FormatLocaleString(buffer,MagickPathExtent,"%s%sgsdll32.dll",
1244 directory,DirectorySeparator);
1245 if (IsPathAccessible(buffer) != MagickFalse)
1247 directory=DestroyString(directory);
1248 (void) CopyMagickString(value,buffer,length);
1249 if (is_64_bit != NULL)
1253 (void) FormatLocaleString(buffer,MagickPathExtent,"%s%sgsdll64.dll",
1254 directory,DirectorySeparator);
1255 if (IsPathAccessible(buffer) != MagickFalse)
1257 directory=DestroyString(directory);
1258 (void) CopyMagickString(value,buffer,length);
1259 if (is_64_bit != NULL)
1266 if (product_family == NULL)
1269 #if defined(KEY_WOW64_32KEY)
1271 flags=KEY_WOW64_64KEY;
1273 flags=KEY_WOW64_32KEY;
1275 (void) NTLocateGhostscript(flags,&root_index,&product_family,
1276 &major_version,&minor_version);
1277 if (product_family == NULL)
1279 flags=KEY_WOW64_32KEY;
1281 is_64_bit_version=TRUE;
1283 flags=KEY_WOW64_64KEY;
1287 if (product_family == NULL)
1289 (void) NTLocateGhostscript(flags,&root_index,&product_family,
1290 &major_version,&minor_version);
1291 #if !defined(_WIN64)
1292 is_64_bit_version=TRUE;
1295 if (product_family == NULL)
1297 if (is_64_bit != NULL)
1298 *is_64_bit=is_64_bit_version;
1299 (void) FormatLocaleString(buffer,MagickPathExtent,"SOFTWARE\\%s\\%d.%02d",
1300 product_family,major_version,minor_version);
1301 extent=(int) length;
1302 if (NTGetRegistryValue(registry_roots[root_index].hkey,buffer,flags,name,
1303 value,&extent) == 0)
1305 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1306 "registry: \"%s\\%s\\%s\"=\"%s\"",registry_roots[root_index].name,
1313 MagickPrivate int NTGhostscriptDLL(char *path,int length)
1316 dll[MagickPathExtent] = { "" };
1322 if ((*dll == '\0') &&
1323 (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,dll,sizeof(dll)) == FALSE))
1327 if (!is_64_bit_version)
1330 if (is_64_bit_version)
1333 (void) CopyMagickString(path,dll,length);
1338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1342 % N T G h o s t s c r i p t D L L V e c t o r s %
1346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1348 % NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
1349 % function vectors to invoke Ghostscript DLL functions. A null pointer is
1350 % returned if there is an error when loading the DLL or retrieving the
1353 % The format of the NTGhostscriptDLLVectors method is:
1355 % const GhostInfo *NTGhostscriptDLLVectors(void)
1358 MagickPrivate const GhostInfo *NTGhostscriptDLLVectors(void)
1360 if (NTGhostscriptLoadDLL() == FALSE)
1361 return((GhostInfo *) NULL);
1362 return(&ghost_info);
1366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1370 % N T G h o s t s c r i p t E X E %
1374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1376 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1377 % The method returns FALSE if a full path value is not obtained and returns
1378 % a default path of gswin32c.exe.
1380 % The format of the NTGhostscriptEXE method is:
1382 % int NTGhostscriptEXE(char *path,int length)
1384 % A description of each parameter follows:
1386 % o path: return the Ghostscript executable path here.
1388 % o length: length of buffer.
1391 MagickPrivate int NTGhostscriptEXE(char *path,int length)
1397 program[MagickPathExtent] = { "" };
1400 is_64_bit_version = FALSE;
1402 (void) CopyMagickString(path,"gswin32c.exe",length);
1403 if (*program == '\0')
1405 if (ghost_semaphore == (SemaphoreInfo *) NULL)
1406 ActivateSemaphoreInfo(&ghost_semaphore);
1407 LockSemaphoreInfo(ghost_semaphore);
1408 if (*program == '\0')
1410 if (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,program,
1411 sizeof(program)) == FALSE)
1413 UnlockSemaphoreInfo(ghost_semaphore);
1416 p=strrchr(program,'\\');
1417 if (p != (char *) NULL)
1421 (void) ConcatenateMagickString(program,is_64_bit_version ?
1422 "gswin64c.exe" : "gswin32c.exe",sizeof(program));
1425 UnlockSemaphoreInfo(ghost_semaphore);
1427 (void) CopyMagickString(path,program,length);
1432 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1436 % N T G h o s t s c r i p t F o n t s %
1440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1442 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1443 % returns FALSE if it cannot determine the font path.
1445 % The format of the NTGhostscriptFonts method is:
1447 % int NTGhostscriptFonts(char *path, int length)
1449 % A description of each parameter follows:
1451 % o path: return the font path here.
1453 % o length: length of the path buffer.
1456 MagickPrivate int NTGhostscriptFonts(char *path,int length)
1459 buffer[MagickPathExtent],
1461 filename[MagickPathExtent];
1468 directory=GetEnvironmentValue("MAGICK_GHOSTSCRIPT_FONT_PATH");
1469 if (directory != (char *) NULL)
1471 (void) CopyMagickString(buffer,directory,MagickPathExtent);
1472 directory=DestroyString(directory);
1476 if (NTGhostscriptGetString("GS_LIB",NULL,buffer,MagickPathExtent) == FALSE)
1479 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1481 (void) CopyMagickString(path,p+1,length+1);
1482 q=strchr(path,DirectoryListSeparator);
1483 if (q != (char *) NULL)
1485 (void) FormatLocaleString(filename,MagickPathExtent,"%s%sfonts.dir",path,
1486 DirectorySeparator);
1487 if (IsPathAccessible(filename) != MagickFalse)
1495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1499 % N T G h o s t s c r i p t L o a d D L L %
1503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1505 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1506 % TRUE if it succeeds.
1508 % The format of the NTGhostscriptLoadDLL method is:
1510 % int NTGhostscriptLoadDLL(void)
1513 static inline int NTGhostscriptHasValidHandle()
1515 if ((nt_ghost_info.delete_instance == NULL) || (ghost_info.exit == NULL) ||
1516 (ghost_info.init_with_args == NULL) ||
1517 (nt_ghost_info.new_instance == NULL) ||
1518 (ghost_info.run_string == NULL) || (ghost_info.set_stdio == NULL) ||
1519 (ghost_info.revision == NULL))
1526 MagickPrivate int NTGhostscriptLoadDLL(void)
1529 path[MagickPathExtent];
1531 if (ghost_semaphore == (SemaphoreInfo *) NULL)
1532 ActivateSemaphoreInfo(&ghost_semaphore);
1533 LockSemaphoreInfo(ghost_semaphore);
1534 if (ghost_handle != (void *) NULL)
1536 UnlockSemaphoreInfo(ghost_semaphore);
1537 return(NTGhostscriptHasValidHandle());
1539 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1541 UnlockSemaphoreInfo(ghost_semaphore);
1544 ghost_handle=lt_dlopen(path);
1545 if (ghost_handle == (void *) NULL)
1547 UnlockSemaphoreInfo(ghost_semaphore);
1550 (void) memset((void *) &nt_ghost_info,0,sizeof(NTGhostInfo));
1551 nt_ghost_info.delete_instance=(void (MagickDLLCall *)(gs_main_instance *)) (
1552 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1553 nt_ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,
1554 void *)) (lt_dlsym(ghost_handle,"gsapi_new_instance"));
1555 nt_ghost_info.has_instance=MagickFalse;
1556 (void) memset((void *) &ghost_info,0,sizeof(GhostInfo));
1557 ghost_info.delete_instance=NTGhostscriptDeleteInstance;
1558 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1559 lt_dlsym(ghost_handle,"gsapi_exit");
1560 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1561 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1562 ghost_info.new_instance=NTGhostscriptNewInstance;
1563 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1564 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1565 ghost_info.set_stdio=(int (MagickDLLCall *)(gs_main_instance *,int(
1566 MagickDLLCall *)(void *,char *,int),int(MagickDLLCall *)(void *,
1567 const char *,int),int(MagickDLLCall *)(void *,const char *,int)))
1568 (lt_dlsym(ghost_handle,"gsapi_set_stdio"));
1569 ghost_info.revision=(int (MagickDLLCall *)(gsapi_revision_t *,int)) (
1570 lt_dlsym(ghost_handle,"gsapi_revision"));
1571 UnlockSemaphoreInfo(ghost_semaphore);
1572 return(NTGhostscriptHasValidHandle());
1576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1580 % N T G h o s t s c r i p t U n L o a d D L L %
1584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1586 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1589 % The format of the NTGhostscriptUnLoadDLL method is:
1591 % int NTGhostscriptUnLoadDLL(void)
1594 MagickPrivate void NTGhostscriptUnLoadDLL(void)
1596 if (ghost_semaphore == (SemaphoreInfo *) NULL)
1597 ActivateSemaphoreInfo(&ghost_semaphore);
1598 LockSemaphoreInfo(ghost_semaphore);
1599 if (ghost_handle != (void *) NULL)
1601 (void) lt_dlclose(ghost_handle);
1602 ghost_handle=(void *) NULL;
1603 (void) memset((void *) &ghost_info,0,sizeof(GhostInfo));
1605 UnlockSemaphoreInfo(ghost_semaphore);
1606 RelinquishSemaphoreInfo(&ghost_semaphore);
1610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1614 % N T I n i t i a l i z e L i b r a r y %
1618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1620 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1622 % The format of the NTInitializeLibrary method is:
1624 % int NTInitializeLibrary(void)
1627 MagickPrivate int NTInitializeLibrary(void)
1633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1637 % N T I n i t i a l i z e W i n s o c k %
1641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1643 % NTInitializeWinsock() initializes Winsock.
1645 % The format of the NTInitializeWinsock method is:
1647 % void NTInitializeWinsock(void)
1650 MagickPrivate void NTInitializeWinsock(MagickBooleanType use_lock)
1654 if (winsock_semaphore == (SemaphoreInfo *) NULL)
1655 ActivateSemaphoreInfo(&winsock_semaphore);
1656 LockSemaphoreInfo(winsock_semaphore);
1658 if (wsaData == (WSADATA *) NULL)
1660 wsaData=(WSADATA *) AcquireMagickMemory(sizeof(WSADATA));
1661 if (WSAStartup(MAKEWORD(2,2),wsaData) != 0)
1662 ThrowFatalException(CacheFatalError,"WSAStartup failed");
1665 UnlockSemaphoreInfo(winsock_semaphore);
1669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1673 + N T M a p M e m o r y %
1677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1679 % Mmap() emulates the Unix method of the same name.
1681 % The format of the NTMapMemory method is:
1683 % MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1684 % int access,int file,MagickOffsetType offset)
1687 MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1688 int flags,int file,MagickOffsetType offset)
1707 file_handle=INVALID_HANDLE_VALUE;
1708 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1709 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1710 map_handle=INVALID_HANDLE_VALUE;
1712 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1713 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1715 if (protection & PROT_WRITE)
1717 access_mode=FILE_MAP_WRITE;
1718 if (!(flags & MAP_PRIVATE))
1719 protection_mode=PAGE_READWRITE;
1722 access_mode=FILE_MAP_COPY;
1723 protection_mode=PAGE_WRITECOPY;
1727 if (protection & PROT_READ)
1729 access_mode=FILE_MAP_READ;
1730 protection_mode=PAGE_READONLY;
1732 if ((file == -1) && (flags & MAP_ANONYMOUS))
1733 file_handle=INVALID_HANDLE_VALUE;
1735 file_handle=(HANDLE) _get_osfhandle(file);
1736 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1740 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1742 CloseHandle(map_handle);
1744 if (map == (void *) NULL)
1745 return((void *) ((char *) MAP_FAILED));
1746 return((void *) ((char *) map));
1750 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1754 % N T O p e n D i r e c t o r y %
1758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1760 % NTOpenDirectory() opens the directory named by filename and associates a
1761 % directory stream with it.
1763 % The format of the NTOpenDirectory method is:
1765 % DIR *NTOpenDirectory(const char *path)
1767 % A description of each parameter follows:
1769 % o entry: Specifies a pointer to a DIR structure.
1772 MagickPrivate DIR *NTOpenDirectory(const char *path)
1781 file_specification[MagickPathExtent];
1783 assert(path != (const char *) NULL);
1784 length=MultiByteToWideChar(CP_UTF8,0,path,-1,file_specification,
1787 return((DIR *) NULL);
1788 if (wcsncat(file_specification,(const wchar_t*) DirectorySeparator,
1789 MagickPathExtent-wcslen(file_specification)-1) == (wchar_t*) NULL)
1790 return((DIR *) NULL);
1791 entry=(DIR *) AcquireCriticalMemory(sizeof(DIR));
1792 entry->firsttime=TRUE;
1793 entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
1794 if (entry->hSearch == INVALID_HANDLE_VALUE)
1796 if(wcsncat(file_specification,L"*.*",
1797 MagickPathExtent-wcslen(file_specification)-1) == (wchar_t*) NULL)
1799 entry=(DIR *) RelinquishMagickMemory(entry);
1800 return((DIR *) NULL);
1802 entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
1803 if (entry->hSearch == INVALID_HANDLE_VALUE)
1805 entry=(DIR *) RelinquishMagickMemory(entry);
1806 return((DIR *) NULL);
1813 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1817 % N T O p e n L i b r a r y %
1821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1823 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1824 % can be used to access the various procedures in the module.
1826 % The format of the NTOpenLibrary method is:
1828 % void *NTOpenLibrary(const char *filename)
1830 % A description of each parameter follows:
1832 % o path: Specifies a pointer to string representing dynamic module that
1837 static inline const char *GetSearchPath(void)
1839 #if defined(MAGICKCORE_LTDL_DELEGATE)
1840 return(lt_dlgetsearchpath());
1842 return(lt_slsearchpath);
1846 static UINT ChangeErrorMode(void)
1849 (CALLBACK *GETERRORMODE)(void);
1860 mode=SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1862 handle=GetModuleHandle("kernel32.dll");
1863 if (handle == (HMODULE) NULL)
1864 return SetErrorMode(mode);
1866 getErrorMode=(GETERRORMODE) NTGetLibrarySymbol(handle,"GetErrorMode");
1867 if (getErrorMode != (GETERRORMODE) NULL)
1868 mode=getErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1870 return SetErrorMode(mode);
1873 static inline void *NTLoadLibrary(const char *filename)
1879 path[MagickPathExtent];
1881 length=MultiByteToWideChar(CP_UTF8,0,filename,-1,path,MagickPathExtent);
1883 return((void *) NULL);
1884 return (void *) LoadLibraryExW(path,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1887 MagickPrivate void *NTOpenLibrary(const char *filename)
1890 path[MagickPathExtent];
1902 mode=ChangeErrorMode();
1903 handle=NTLoadLibrary(filename);
1904 if (handle == (void *) NULL)
1907 while (p != (const char*) NULL)
1909 q=strchr(p,DirectoryListSeparator);
1910 if (q != (const char*) NULL)
1911 (void) CopyMagickString(path,p,q-p+1);
1913 (void) CopyMagickString(path,p,MagickPathExtent);
1914 (void) ConcatenateMagickString(path,DirectorySeparator,MagickPathExtent);
1915 (void) ConcatenateMagickString(path,filename,MagickPathExtent);
1916 handle=NTLoadLibrary(path);
1917 if (handle != (void *) NULL || q == (const char*) NULL)
1927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1931 % N T R e a d D i r e c t o r y %
1935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1937 % NTReadDirectory() returns a pointer to a structure representing the
1938 % directory entry at the current position in the directory stream to which
1941 % The format of the NTReadDirectory
1943 % NTReadDirectory(entry)
1945 % A description of each parameter follows:
1947 % o entry: Specifies a pointer to a DIR structure.
1950 MagickPrivate struct dirent *NTReadDirectory(DIR *entry)
1958 if (entry == (DIR *) NULL)
1959 return((struct dirent *) NULL);
1960 if (!entry->firsttime)
1962 status=FindNextFileW(entry->hSearch,&entry->Win32FindData);
1964 return((struct dirent *) NULL);
1966 length=WideCharToMultiByte(CP_UTF8,0,entry->Win32FindData.cFileName,-1,
1967 entry->file_info.d_name,sizeof(entry->file_info.d_name),NULL,NULL);
1969 return((struct dirent *) NULL);
1970 entry->firsttime=FALSE;
1971 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1972 return(&entry->file_info);
1976 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1980 % N T R e g i s t r y K e y L o o k u p %
1984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1986 % NTRegistryKeyLookup() returns ImageMagick installation path settings
1987 % stored in the Windows Registry. Path settings are specific to the
1988 % installed ImageMagick version so that multiple Image Magick installations
1991 % Values are stored in the registry under a base path path similar to
1992 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\6.7.4\Q:16" or
1993 % "HKEY_CURRENT_USER/SOFTWARE\ImageMagick\6.7.4\Q:16". The provided subkey
1994 % is appended to this base path to form the full key.
1996 % The format of the NTRegistryKeyLookup method is:
1998 % unsigned char *NTRegistryKeyLookup(const char *subkey)
2000 % A description of each parameter follows:
2002 % o subkey: Specifies a string that identifies the registry object.
2003 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
2004 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
2007 MagickPrivate unsigned char *NTRegistryKeyLookup(const char *subkey)
2010 package_key[MagickPathExtent];
2028 (void) FormatLocaleString(package_key,MagickPathExtent,
2029 "SOFTWARE\\%s\\%s\\Q:%d",MagickPackageName,MagickLibVersionText,
2030 MAGICKCORE_QUANTUM_DEPTH);
2031 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
2032 registry_key=(HKEY) INVALID_HANDLE_VALUE;
2033 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
2034 if (status != ERROR_SUCCESS)
2035 status=RegOpenKeyExA(HKEY_CURRENT_USER,package_key,0,KEY_READ,
2037 if (status != ERROR_SUCCESS)
2038 return((unsigned char *) NULL);
2043 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
2044 if (value == (unsigned char *) NULL)
2046 RegCloseKey(registry_key);
2047 return((unsigned char *) NULL);
2049 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
2050 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2051 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
2053 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
2054 if (value == (BYTE *) NULL)
2056 RegCloseKey(registry_key);
2057 return((unsigned char *) NULL);
2059 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2061 RegCloseKey(registry_key);
2062 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
2063 value=(unsigned char *) RelinquishMagickMemory(value);
2064 return((unsigned char *) value);
2068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2072 % N T R e p o r t E v e n t %
2076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2078 % NTReportEvent() reports an event.
2080 % The format of the NTReportEvent method is:
2082 % MagickBooleanType NTReportEvent(const char *event,
2083 % const MagickBooleanType error)
2085 % A description of each parameter follows:
2087 % o event: the event.
2089 % o error: MagickTrue the event is an error.
2092 MagickPrivate MagickBooleanType NTReportEvent(const char *event,
2093 const MagickBooleanType error)
2104 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
2106 return(MagickFalse);
2108 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
2109 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
2110 DeregisterEventSource(handle);
2115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2119 % N T R e s o u r c e T o B l o b %
2123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2125 % NTResourceToBlob() returns a blob containing the contents of the resource
2126 % in the current executable specified by the id parameter. This currently
2127 % used to retrieve MGK files tha have been embedded into the various command
2130 % The format of the NTResourceToBlob method is:
2132 % unsigned char *NTResourceToBlob(const char *id)
2134 % A description of each parameter follows:
2136 % o id: Specifies a string that identifies the resource.
2139 MagickPrivate unsigned char *NTResourceToBlob(const char *id)
2142 #ifndef MAGICKCORE_LIBRARY_NAME
2144 path[MagickPathExtent];
2163 assert(id != (const char *) NULL);
2164 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
2165 #ifdef MAGICKCORE_LIBRARY_NAME
2166 handle=GetModuleHandle(MAGICKCORE_LIBRARY_NAME);
2168 (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",GetClientPath(),
2169 DirectorySeparator,GetClientName());
2170 if (IsPathAccessible(path) != MagickFalse)
2171 handle=GetModuleHandle(path);
2173 handle=GetModuleHandle(0);
2176 return((unsigned char *) NULL);
2177 resource=FindResource(handle,id,"IMAGEMAGICK");
2179 return((unsigned char *) NULL);
2180 global=LoadResource(handle,resource);
2182 return((unsigned char *) NULL);
2183 length=SizeofResource(handle,resource);
2184 value=(unsigned char *) LockResource(global);
2187 FreeResource(global);
2188 return((unsigned char *) NULL);
2190 blob=(unsigned char *) AcquireQuantumMemory(length+MagickPathExtent,
2192 if (blob != (unsigned char *) NULL)
2194 (void) memcpy(blob,value,length);
2197 UnlockResource(global);
2198 FreeResource(global);
2203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2207 % N T S e e k D i r e c t o r y %
2211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2213 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
2214 % on the directory stream.
2216 % The format of the NTSeekDirectory method is:
2218 % void NTSeekDirectory(DIR *entry,ssize_t position)
2220 % A description of each parameter follows:
2222 % o entry: Specifies a pointer to a DIR structure.
2224 % o position: specifies the position associated with the directory
2228 MagickPrivate void NTSeekDirectory(DIR *entry,ssize_t position)
2230 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2231 assert(entry != (DIR *) NULL);
2237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2241 % N T S e t S e a r c h P a t h %
2245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2247 % NTSetSearchPath() sets the current locations that the subsystem should
2248 % look at to find dynamically loadable modules.
2250 % The format of the NTSetSearchPath method is:
2252 % int NTSetSearchPath(const char *path)
2254 % A description of each parameter follows:
2256 % o path: Specifies a pointer to string representing the search path
2257 % for DLL's that can be dynamically loaded.
2260 MagickPrivate int NTSetSearchPath(const char *path)
2262 #if defined(MAGICKCORE_LTDL_DELEGATE)
2263 lt_dlsetsearchpath(path);
2265 if (lt_slsearchpath != (char *) NULL)
2266 lt_slsearchpath=DestroyString(lt_slsearchpath);
2267 if (path != (char *) NULL)
2268 lt_slsearchpath=AcquireString(path);
2274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2278 + N T S y n c M e m o r y %
2282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2284 % NTSyncMemory() emulates the Unix method of the same name.
2286 % The format of the NTSyncMemory method is:
2288 % int NTSyncMemory(void *address,size_t length,int flags)
2290 % A description of each parameter follows:
2292 % o address: the address of the binary large object.
2294 % o length: the length of the binary large object.
2296 % o flags: Option flags (ignored for Windows).
2299 MagickPrivate int NTSyncMemory(void *address,size_t length,int flags)
2302 if (FlushViewOfFile(address,length) == MagickFalse)
2308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2312 % N T S y s t e m C o m m a n d %
2316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2318 % NTSystemCommand() executes the specified command and waits until it
2319 % terminates. The returned value is the exit status of the command.
2321 % The format of the NTSystemCommand method is:
2323 % int NTSystemCommand(MagickFalse,const char *command)
2325 % A description of each parameter follows:
2327 % o command: This string is the command to execute.
2329 % o output: an optional buffer to store the output from stderr/stdout.
2332 MagickPrivate int NTSystemCommand(const char *command,char *output)
2334 #define CleanupOutputHandles \
2335 if (read_output != (HANDLE) NULL) \
2337 CloseHandle(read_output); \
2338 read_output=(HANDLE) NULL; \
2339 CloseHandle(write_output); \
2340 write_output=(HANDLE) NULL; \
2343 #define CopyLastError \
2344 if (output != (char *) NULL) \
2346 error=NTGetLastError(); \
2347 if (error != (char *) NULL) \
2349 CopyMagickString(output,error,MagickPathExtent); \
2350 error=DestroyString(error); \
2356 local_command[MagickPathExtent];
2382 if (command == (char *) NULL)
2384 read_output=(HANDLE) NULL;
2385 write_output=(HANDLE) NULL;
2386 GetStartupInfo(&startup_info);
2387 startup_info.dwFlags=STARTF_USESHOWWINDOW;
2388 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
2389 (void) CopyMagickString(local_command,command,MagickPathExtent);
2390 asynchronous=command[strlen(command)-1] == '&' ? MagickTrue : MagickFalse;
2391 if (asynchronous != MagickFalse)
2393 local_command[strlen(command)-1]='\0';
2394 startup_info.wShowWindow=SW_SHOWDEFAULT;
2398 if (command[strlen(command)-1] == '|')
2399 local_command[strlen(command)-1]='\0';
2401 startup_info.wShowWindow=SW_HIDE;
2402 read_output=(HANDLE) NULL;
2403 if (output != (char *) NULL)
2405 sa.nLength=sizeof(SECURITY_ATTRIBUTES);
2406 sa.bInheritHandle=TRUE;
2407 sa.lpSecurityDescriptor=NULL;
2408 if (CreatePipe(&read_output,&write_output,NULL,0))
2410 if (SetHandleInformation(write_output,HANDLE_FLAG_INHERIT,
2411 HANDLE_FLAG_INHERIT))
2413 startup_info.dwFlags|=STARTF_USESTDHANDLES;
2414 startup_info.hStdOutput=write_output;
2415 startup_info.hStdError=write_output;
2418 CleanupOutputHandles;
2421 read_output=(HANDLE) NULL;
2424 status=CreateProcess((LPCTSTR) NULL,local_command,(LPSECURITY_ATTRIBUTES)
2425 NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) TRUE,(DWORD)
2426 NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
2431 CleanupOutputHandles;
2434 if (asynchronous != MagickFalse)
2435 return(status == 0);
2436 status=WaitForSingleObject(process_info.hProcess,INFINITE);
2437 if (status != WAIT_OBJECT_0)
2440 CleanupOutputHandles;
2443 status=GetExitCodeProcess(process_info.hProcess,&child_status);
2447 CleanupOutputHandles;
2450 CloseHandle(process_info.hProcess);
2451 CloseHandle(process_info.hThread);
2452 if (read_output != (HANDLE) NULL)
2453 if (PeekNamedPipe(read_output,(LPVOID) NULL,0,(LPDWORD) NULL,&size,
2455 if ((size > 0) && (ReadFile(read_output,output,MagickPathExtent-1,
2457 output[bytes_read]='\0';
2458 CleanupOutputHandles;
2459 return((int) child_status);
2463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2467 % N T S y s t e m C o n i f i g u r a t i o n %
2471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2473 % NTSystemConfiguration() provides a way for the application to determine
2474 % values for system limits or options at runtime.
2476 % The format of the exit method is:
2478 % ssize_t NTSystemConfiguration(int name)
2480 % A description of each parameter follows:
2482 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
2485 MagickPrivate ssize_t NTSystemConfiguration(int name)
2494 GetSystemInfo(&system_info);
2495 return(system_info.dwPageSize);
2497 case _SC_PHYS_PAGES:
2511 handle=GetModuleHandle("kernel32.dll");
2512 if (handle == (HMODULE) NULL)
2514 GetSystemInfo(&system_info);
2515 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
2516 if (module == (LPFNDLLFUNC2) NULL)
2521 GlobalMemoryStatus(&global_status);
2522 return((ssize_t) global_status.dwTotalPhys/system_info.dwPageSize/4);
2524 status.dwLength=sizeof(status);
2525 if (module(&status) == 0)
2527 return((ssize_t) status.ullTotalPhys/system_info.dwPageSize/4);
2538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2542 % N T T e l l D i r e c t o r y %
2546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2548 % NTTellDirectory() returns the current location associated with the named
2551 % The format of the NTTellDirectory method is:
2553 % ssize_t NTTellDirectory(DIR *entry)
2555 % A description of each parameter follows:
2557 % o entry: Specifies a pointer to a DIR structure.
2560 MagickPrivate ssize_t NTTellDirectory(DIR *entry)
2562 assert(entry != (DIR *) NULL);
2567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2571 % N T T r u n c a t e F i l e %
2575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2577 % NTTruncateFile() truncates a file to a specified length.
2579 % The format of the NTTruncateFile method is:
2581 % int NTTruncateFile(int file,off_t length)
2583 % A description of each parameter follows:
2587 % o length: the file length.
2590 MagickPrivate int NTTruncateFile(int file,off_t length)
2602 file_handle=(HANDLE) _get_osfhandle(file);
2603 if (file_handle == INVALID_HANDLE_VALUE)
2605 low=(long) (length & 0xffffffffUL);
2606 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2607 file_pointer=SetFilePointer(file_handle,low,&high,FILE_BEGIN);
2608 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2610 if (SetEndOfFile(file_handle) == 0)
2616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2620 + N T U n m a p M e m o r y %
2624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2626 % NTUnmapMemory() emulates the Unix munmap method.
2628 % The format of the NTUnmapMemory method is:
2630 % int NTUnmapMemory(void *map,size_t length)
2632 % A description of each parameter follows:
2634 % o map: the address of the binary large object.
2636 % o length: the length of the binary large object.
2639 MagickPrivate int NTUnmapMemory(void *map,size_t length)
2642 if (UnmapViewOfFile(map) == 0)
2648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2652 % N T U s e r T i m e %
2656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2658 % NTUserTime() returns the total time the process has been scheduled (e.g.
2659 % seconds) since the last call to StartTimer().
2661 % The format of the UserTime method is:
2663 % double NTUserTime(void)
2666 MagickPrivate double NTUserTime(void)
2696 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2697 GetVersionEx(&OsVersionInfo);
2698 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2699 return(NTElapsedTime());
2700 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2701 &kernel_time.filetime,&user_time.filetime);
2704 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2712 % N T W a r n i n g H a n d l e r %
2716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2718 % NTWarningHandler() displays a warning reason.
2720 % The format of the NTWarningHandler method is:
2722 % void NTWarningHandler(const ExceptionType severity,const char *reason,
2723 % const char *description)
2725 % A description of each parameter follows:
2727 % o severity: Specifies the numeric warning category.
2729 % o reason: Specifies the reason to display before terminating the
2732 % o description: Specifies any description to the reason.
2735 MagickPrivate void NTWarningHandler(const ExceptionType severity,
2736 const char *reason,const char *description)
2739 buffer[2*MagickPathExtent];
2742 if (reason == (char *) NULL)
2744 if (description == (char *) NULL)
2745 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s.\n",GetClientName(),
2748 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s (%s).\n",
2749 GetClientName(),reason,description);
2750 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2751 MB_SETFOREGROUND | MB_ICONINFORMATION);
2755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2759 % N T W i n d o w s G e n e s i s %
2763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2765 % NTWindowsGenesis() initializes the MagickCore Windows environment.
2767 % The format of the NTWindowsGenesis method is:
2769 % void NTWindowsGenesis(void)
2773 static LONG WINAPI NTUncaughtException(EXCEPTION_POINTERS *info)
2775 magick_unreferenced(info);
2776 AsynchronousResourceComponentTerminus();
2777 return(EXCEPTION_CONTINUE_SEARCH);
2780 MagickPrivate void NTWindowsGenesis(void)
2785 SetUnhandledExceptionFilter(NTUncaughtException);
2786 mode=GetEnvironmentValue("MAGICK_ERRORMODE");
2787 if (mode != (char *) NULL)
2789 (void) SetErrorMode(StringToInteger(mode));
2790 mode=DestroyString(mode);
2792 #if defined(_DEBUG) && !defined(__BORLANDC__) && !defined(__MINGW32__)
2793 if (IsEventLogging() != MagickFalse)
2798 debug=_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
2799 debug|=_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF |
2800 _CRTDBG_LEAK_CHECK_DF;
2801 (void) _CrtSetDbgFlag(debug);
2802 _ASSERTE(_CrtCheckMemory());
2805 #if defined(MAGICKCORE_INSTALLED_SUPPORT)
2810 path=NTRegistryKeyLookup("LibPath");
2811 if (path != (unsigned char *) NULL)
2817 lib_path[MagickPathExtent];
2819 length=MultiByteToWideChar(CP_UTF8,0,(char *) path,-1,lib_path,
2822 SetDllDirectoryW(lib_path);
2823 path=(unsigned char *) RelinquishMagickMemory(path);
2830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2834 % N T W i n d o w s T e r m i n u s %
2838 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2840 % NTWindowsTerminus() terminates the MagickCore Windows environment.
2842 % The format of the NTWindowsTerminus method is:
2844 % void NTWindowsTerminus(void)
2847 MagickPrivate void NTWindowsTerminus(void)
2849 NTGhostscriptUnLoadDLL();
2850 if (winsock_semaphore == (SemaphoreInfo *) NULL)
2851 ActivateSemaphoreInfo(&winsock_semaphore);
2852 LockSemaphoreInfo(winsock_semaphore);
2853 if (wsaData != (WSADATA *) NULL)
2856 wsaData=(WSADATA *) RelinquishMagickMemory((void *) wsaData);
2858 UnlockSemaphoreInfo(winsock_semaphore);
2859 RelinquishSemaphoreInfo(&winsock_semaphore);