2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Windows NT Utility Methods for MagickCore %
20 % Copyright 1999-2017 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 % http://www.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/nt-base.h"
50 #include "MagickCore/nt-base-private.h"
51 #include "MagickCore/resource_.h"
52 #include "MagickCore/resource-private.h"
53 #include "MagickCore/timer.h"
54 #include "MagickCore/string_.h"
55 #include "MagickCore/string-private.h"
56 #include "MagickCore/utility.h"
57 #include "MagickCore/utility-private.h"
58 #include "MagickCore/version.h"
59 #if defined(MAGICKCORE_LTDL_DELEGATE)
62 #if defined(MAGICKCORE_CIPHER_SUPPORT)
70 #if !defined(MAP_FAILED)
71 #define MAP_FAILED ((void *)(LONG_PTR)-1)
79 We need to make sure only one instance is created for each process and that
80 is why we wrap the new/delete instance methods.
82 From: http://www.ghostscript.com/doc/current/API.htm
83 "The Win32 DLL gsdll32.dll can be used by multiple programs simultaneously,
84 but only once within each process"
86 typedef struct _NTGhostInfo
89 (MagickDLLCall *delete_instance)(gs_main_instance *);
92 (MagickDLLCall *new_instance)(gs_main_instance **,void *);
101 #if !defined(MAGICKCORE_LTDL_DELEGATE)
103 *lt_slsearchpath = (char *) NULL;
113 *ghost_handle = (void *) NULL;
116 *ghost_semaphore = (SemaphoreInfo *) NULL,
117 *winsock_semaphore = (SemaphoreInfo *) NULL;
120 *wsaData = (WSADATA*) NULL;
130 const registry_roots[2] =
132 { HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
133 { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
137 External declarations.
139 #if !defined(MAGICKCORE_WINDOWS_SUPPORT)
140 extern "C" BOOL WINAPI
141 DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved);
144 static void MagickDLLCall NTGhostscriptDeleteInstance(
145 gs_main_instance *instance)
147 LockSemaphoreInfo(ghost_semaphore);
148 nt_ghost_info.delete_instance(instance);
149 nt_ghost_info.has_instance=MagickFalse;
150 UnlockSemaphoreInfo(ghost_semaphore);
153 static int MagickDLLCall NTGhostscriptNewInstance(gs_main_instance **pinstance,
159 LockSemaphoreInfo(ghost_semaphore);
161 if (nt_ghost_info.has_instance == MagickFalse)
163 status=nt_ghost_info.new_instance(pinstance,caller_handle);
165 nt_ghost_info.has_instance=MagickTrue;
167 UnlockSemaphoreInfo(ghost_semaphore);
171 static inline char *create_utf8_string(const wchar_t *wideChar)
179 count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,NULL,0,NULL,NULL);
181 return((char *) NULL);
182 utf8=(char *) AcquireQuantumMemory(count+1,sizeof(*utf8));
183 if (utf8 == (char *) NULL)
184 return((char *) NULL);
185 count=WideCharToMultiByte(CP_UTF8,0,wideChar,-1,utf8,count,NULL,NULL);
188 utf8=DestroyString(utf8);
189 return((char *) NULL);
196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 % DllMain() is an entry point to the DLL which is called when processes and
207 % threads are initialized and terminated, or upon calls to the Windows
208 % LoadLibrary and FreeLibrary functions.
210 % The function returns TRUE of it succeeds, or FALSE if initialization fails.
212 % The format of the DllMain method is:
214 % BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
216 % A description of each parameter follows:
218 % o handle: handle to the DLL module
220 % o reason: reason for calling function:
222 % DLL_PROCESS_ATTACH - DLL is being loaded into virtual address
223 % space of current process.
224 % DLL_THREAD_ATTACH - Indicates that the current process is
225 % creating a new thread. Called under the
226 % context of the new thread.
227 % DLL_THREAD_DETACH - Indicates that the thread is exiting.
228 % Called under the context of the exiting
230 % DLL_PROCESS_DETACH - Indicates that the DLL is being unloaded
231 % from the virtual address space of the
234 % o lpvReserved: Used for passing additional info during DLL_PROCESS_ATTACH
235 % and DLL_PROCESS_DETACH.
238 #if defined(_DLL) && defined(ProvideDllMain)
239 BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
243 case DLL_PROCESS_ATTACH:
254 MagickCoreGenesis((const char *) NULL,MagickFalse);
255 wide_path=(wchar_t *) AcquireQuantumMemory(MagickPathExtent,
257 if (wide_path == (wchar_t *) NULL)
259 count=(ssize_t) GetModuleFileNameW(handle,wide_path,MagickPathExtent);
265 module_path=create_utf8_string(wide_path);
266 for ( ; count > 0; count--)
267 if (module_path[count] == '\\')
269 module_path[count+1]='\0';
272 path=(char *) AcquireQuantumMemory(16UL*MagickPathExtent,sizeof(*path));
273 if (path == (char *) NULL)
275 module_path=DestroyString(module_path);
276 wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
279 count=(ssize_t) GetEnvironmentVariable("PATH",path,16*MagickPathExtent);
280 if ((count != 0) && (strstr(path,module_path) == (char *) NULL))
282 if ((strlen(module_path)+count+1) < (16*MagickPathExtent-1))
287 variable=(char *) AcquireQuantumMemory(16UL*MagickPathExtent,
289 if (variable == (char *) NULL)
291 path=DestroyString(path);
292 module_path=DestroyString(module_path);
293 wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
296 (void) FormatLocaleString(variable,16*MagickPathExtent,
297 "%s;%s",module_path,path);
298 SetEnvironmentVariable("PATH",variable);
299 variable=DestroyString(variable);
302 path=DestroyString(path);
303 module_path=DestroyString(module_path);
305 wide_path=(wchar_t *) RelinquishMagickMemory(wide_path);
308 case DLL_PROCESS_DETACH:
310 MagickCoreTerminus();
321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 % Exit() calls TerminateProcess for Win95.
333 % The format of the exit method is:
335 % int Exit(int status)
337 % A description of each parameter follows:
339 % o status: an integer value representing the status of the terminating
343 MagickPrivate int Exit(int status)
347 TerminateProcess(GetCurrentProcess(),(unsigned int) status);
353 #if !defined(__MINGW32__) && !defined(__MINGW64__)
355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359 % g e t t i m e o f d a y %
363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365 % The gettimeofday() method get the time of day.
367 % The format of the gettimeofday method is:
369 % int gettimeofday(struct timeval *time_value,struct timezone *time_zone)
371 % A description of each parameter follows:
373 % o time_value: the time value.
375 % o time_zone: the time zone.
378 MagickPrivate int gettimeofday (struct timeval *time_value,
379 struct timezone *time_zone)
381 #define EpochFiletime MagickLLConstant(116444736000000000)
386 if (time_value != (struct timeval *) NULL)
397 GetSystemTimeAsFileTime(&file_time);
398 date_time.LowPart=file_time.dwLowDateTime;
399 date_time.HighPart=file_time.dwHighDateTime;
400 time=date_time.QuadPart;
403 time_value->tv_sec=(ssize_t) (time / 1000000);
404 time_value->tv_usec=(ssize_t) (time % 1000000);
406 if (time_zone != (struct timezone *) NULL)
413 time_zone->tz_minuteswest=_timezone/60;
414 time_zone->tz_dsttime=_daylight;
421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
425 % I s W i n d o w s 9 5 %
429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
431 % IsWindows95() returns true if the system is Windows 95.
433 % The format of the IsWindows95 method is:
438 MagickPrivate int IsWindows95()
443 version_info.dwOSVersionInfoSize=sizeof(version_info);
444 if (GetVersionEx(&version_info) &&
445 (version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS))
451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
455 % N T A r g v T o U T F 8 %
459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
461 % NTArgvToUTF8() converts the wide command line arguments to UTF-8 to ensure
462 % compatibility with Linux.
464 % The format of the NTArgvToUTF8 method is:
466 % char **NTArgvToUTF8(const int argc,wchar_t **argv)
468 % A description of each parameter follows:
470 % o argc: the number of command line arguments.
472 % o argv: the wide-character command line arguments.
475 MagickPrivate char **NTArgvToUTF8(const int argc,wchar_t **argv)
483 utf8=(char **) AcquireQuantumMemory(argc,sizeof(*utf8));
484 if (utf8 == (char **) NULL)
485 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
486 for (i=0; i < (ssize_t) argc; i++)
488 utf8[i]=create_utf8_string(argv[i]);
489 if (utf8[i] == (char *) NULL)
491 for (i--; i >= 0; i--)
492 utf8[i]=DestroyString(utf8[i]);
493 ThrowFatalException(ResourceLimitFatalError,
494 "UnableToConvertStringToARGV");
501 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
505 % N T C l o s e D i r e c t o r y %
509 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
511 % NTCloseDirectory() closes the named directory stream and frees the DIR
514 % The format of the NTCloseDirectory method is:
516 % int NTCloseDirectory(DIR *entry)
518 % A description of each parameter follows:
520 % o entry: Specifies a pointer to a DIR structure.
523 MagickPrivate int NTCloseDirectory(DIR *entry)
525 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
526 assert(entry != (DIR *) NULL);
527 FindClose(entry->hSearch);
528 entry=(DIR *) RelinquishMagickMemory(entry);
532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
536 % N T C l o s e L i b r a r y %
540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
542 % NTCloseLibrary() unloads the module associated with the passed handle.
544 % The format of the NTCloseLibrary method is:
546 % void NTCloseLibrary(void *handle)
548 % A description of each parameter follows:
550 % o handle: Specifies a handle to a previously loaded dynamic module.
553 MagickPrivate int NTCloseLibrary(void *handle)
556 return(FreeLibrary((HINSTANCE) handle));
557 return(!(FreeLibrary((HINSTANCE) handle)));
561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565 % N T C o n t r o l H a n d l e r %
569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
571 % NTControlHandler() registers a control handler that is activated when, for
572 % example, a ctrl-c is received.
574 % The format of the NTControlHandler method is:
576 % int NTControlHandler(void)
580 static BOOL ControlHandler(DWORD type)
583 AsynchronousResourceComponentTerminus();
587 MagickPrivate int NTControlHandler(void)
589 return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
593 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
597 % N T E l a p s e d T i m e %
601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
603 % NTElapsedTime() returns the elapsed time (in seconds) since the last call to
606 % The format of the ElapsedTime method is:
608 % double NTElapsedTime(void)
611 MagickPrivate double NTElapsedTime(void)
625 GetSystemTime(&system_time);
626 SystemTimeToFileTime(&system_time,&elapsed_time.filetime);
627 return((double) 1.0e-7*elapsed_time.filetime64);
631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
641 % NTErf() computes the error function of x.
643 % The format of the NTErf method is:
645 % double NTCloseDirectory(DIR *entry)
647 % A description of each parameter follows:
649 % o x: Specifies a pointer to a DIR structure.
652 MagickPrivate double NTErf(double x)
678 y=1.0-(((((a5*t+a4)*t)+a3)*t+a2)*t+a1)*t*exp(-x*x);
684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
688 + N T E r r o r H a n d l e r %
692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
694 % NTErrorHandler() displays an error reason and then terminates the program.
696 % The format of the NTErrorHandler method is:
698 % void NTErrorHandler(const ExceptionType severity,const char *reason,
699 % const char *description)
701 % A description of each parameter follows:
703 % o severity: Specifies the numeric error category.
705 % o reason: Specifies the reason to display before terminating the
708 % o description: Specifies any description to the reason.
711 MagickPrivate void NTErrorHandler(const ExceptionType severity,
712 const char *reason,const char *description)
715 buffer[3*MagickPathExtent],
719 if (reason == (char *) NULL)
721 MagickCoreTerminus();
724 message=GetExceptionMessage(errno);
725 if ((description != (char *) NULL) && errno)
726 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s (%s) [%s].\n",
727 GetClientName(),reason,description,message);
729 if (description != (char *) NULL)
730 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s (%s).\n",
731 GetClientName(),reason,description);
734 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s [%s].\n",
735 GetClientName(),reason,message);
737 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s.\n",
738 GetClientName(),reason);
739 message=DestroyString(message);
740 (void) MessageBox(NULL,buffer,"ImageMagick Exception",MB_OK | MB_TASKMODAL |
741 MB_SETFOREGROUND | MB_ICONEXCLAMATION);
742 MagickCoreTerminus();
747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 % N T E x i t L i b r a r y %
755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 % NTExitLibrary() exits the dynamic module loading subsystem.
759 % The format of the NTExitLibrary method is:
761 % int NTExitLibrary(void)
764 MagickPrivate int NTExitLibrary(void)
770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
774 % N T G a t h e r R a n d o m D a t a %
778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
780 % NTGatherRandomData() gathers random data and returns it.
782 % The format of the GatherRandomData method is:
784 % MagickBooleanType NTGatherRandomData(const size_t length,
785 % unsigned char *random)
787 % A description of each parameter follows:
789 % length: the length of random data buffer
791 % random: the random data is returned here.
794 MagickPrivate MagickBooleanType NTGatherRandomData(const size_t length,
795 unsigned char *random)
797 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
804 handle=(HCRYPTPROV) NULL;
805 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
806 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET));
808 status=CryptAcquireContext(&handle,NULL,MS_DEF_PROV,PROV_RSA_FULL,
809 (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET));
812 status=CryptGenRandom(handle,(DWORD) length,random);
815 status=CryptReleaseContext(handle,0);
818 status=CryptReleaseContext(handle,0);
829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
833 % N T G e t E x e c u t i o n P a t h %
837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
839 % NTGetExecutionPath() returns the execution path of a program.
841 % The format of the GetExecutionPath method is:
843 % MagickBooleanType NTGetExecutionPath(char *path,const size_t extent)
845 % A description of each parameter follows:
847 % o path: the pathname of the executable that started the process.
849 % o extent: the maximum extent of the path.
852 MagickPrivate MagickBooleanType NTGetExecutionPath(char *path,
856 wide_path[MagickPathExtent];
858 (void) GetModuleFileNameW((HMODULE) NULL,wide_path,(DWORD) extent);
859 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(int) extent,NULL,
865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
869 % N T G e t L a s t E r r o r %
873 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
875 % NTGetLastError() returns the last error that occurred.
877 % The format of the NTGetLastError method is:
879 % char *NTGetLastError(void)
882 char *NTGetLastError(void)
893 status=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
894 FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),
895 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR) &buffer,0,NULL);
897 reason=AcquireString("An unknown error occurred");
900 reason=AcquireString((const char *) buffer);
907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
911 % N T G e t L i b r a r y E r r o r %
915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
917 % Lt_dlerror() returns a pointer to a string describing the last error
918 % associated with a lt_dl method. Note that this function is not thread
919 % safe so it should only be used under the protection of a lock.
921 % The format of the NTGetLibraryError method is:
923 % const char *NTGetLibraryError(void)
926 MagickPrivate const char *NTGetLibraryError(void)
929 last_error[MagickPathExtent];
935 error=NTGetLastError();
937 (void) CopyMagickString(last_error,error,MagickPathExtent);
938 error=DestroyString(error);
943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
947 % N T G e t L i b r a r y S y m b o l %
951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
953 % NTGetLibrarySymbol() retrieve the procedure address of the method
954 % specified by the passed character string.
956 % The format of the NTGetLibrarySymbol method is:
958 % void *NTGetLibrarySymbol(void *handle,const char *name)
960 % A description of each parameter follows:
962 % o handle: Specifies a handle to the previously loaded dynamic module.
964 % o name: Specifies the procedure entry point to be returned.
967 void *NTGetLibrarySymbol(void *handle,const char *name)
972 lpfnDllFunc1=(LPFNDLLFUNC1) GetProcAddress((HINSTANCE) handle,name);
974 return((void *) NULL);
975 return((void *) lpfnDllFunc1);
979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
983 % N T G e t M o d u l e P a t h %
987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989 % NTGetModulePath() returns the path of the specified module.
991 % The format of the GetModulePath method is:
993 % MagickBooleanType NTGetModulePath(const char *module,char *path)
995 % A description of each parameter follows:
997 % modith: the module name.
999 % path: the module path is returned here.
1002 MagickPrivate MagickBooleanType NTGetModulePath(const char *module,char *path)
1005 module_path[MagickPathExtent];
1014 handle=GetModuleHandle(module);
1015 if (handle == (HMODULE) NULL)
1016 return(MagickFalse);
1017 length=GetModuleFileName(handle,module_path,MagickPathExtent);
1019 GetPathComponent(module_path,HeadPath,path);
1024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1028 % N T G h o s t s c r i p t D L L %
1032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1034 % NTGhostscriptDLL() returns the path to the most recent Ghostscript version
1035 % DLL. The method returns TRUE on success otherwise FALSE.
1037 % The format of the NTGhostscriptDLL method is:
1039 % int NTGhostscriptDLL(char *path,int length)
1041 % A description of each parameter follows:
1043 % o path: return the Ghostscript DLL path here.
1045 % o length: the buffer length.
1049 static int NTGetRegistryValue(HKEY root,const char *key,DWORD flags,
1050 const char *name,char *value,int *length)
1067 Get a registry value: key = root\\key, named value = name.
1069 if (RegOpenKeyExA(root,key,0,KEY_READ | flags,&hkey) != ERROR_SUCCESS)
1070 return(1); /* no match */
1074 if (p == (BYTE *) NULL)
1075 p=(&byte); /* ERROR_MORE_DATA only if value is NULL */
1076 status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
1078 if (status == ERROR_SUCCESS)
1081 return(0); /* return the match */
1083 if (status == ERROR_MORE_DATA)
1086 return(-1); /* buffer not large enough */
1088 return(1); /* not found */
1091 static int NTLocateGhostscript(DWORD flags,int *root_index,
1092 const char **product_family,int *major_version,int *minor_version)
1106 "Aladdin Ghostscript"
1110 Find the most recent version of Ghostscript.
1114 *product_family=NULL;
1116 *minor_version=49; /* min version of Ghostscript is 5.50 */
1117 for (i=0; i < (ssize_t) (sizeof(products)/sizeof(products[0])); i++)
1120 key[MagickPathExtent];
1131 (void) FormatLocaleString(key,MagickPathExtent,"SOFTWARE\\%s",products[i]);
1132 for (j=0; j < (ssize_t) (sizeof(registry_roots)/sizeof(registry_roots[0]));
1135 mode=KEY_READ | flags;
1136 if (RegOpenKeyExA(registry_roots[j].hkey,key,0,mode,&hkey) ==
1146 Now enumerate the keys.
1148 extent=sizeof(key)/sizeof(char);
1149 for (k=0; RegEnumKeyA(hkey,k,key,extent) == ERROR_SUCCESS; k++)
1157 if (sscanf(key,"%d.%d",&major,&minor) != 2)
1159 if ((major > *major_version) || ((major == *major_version) &&
1160 (minor > *minor_version)))
1163 *product_family=products[i];
1164 *major_version=major;
1165 *minor_version=minor;
1169 (void) RegCloseKey(hkey);
1173 if (status == MagickFalse)
1178 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
1179 "version %d.%02d",*product_family,*major_version,*minor_version);
1183 static int NTGhostscriptGetString(const char *name,BOOL *is_64_bit,
1184 char *value,const size_t length)
1187 buffer[MagickPathExtent],
1194 *product_family=(const char *) NULL;
1197 is_64_bit_version=FALSE;
1206 Get a string from the installed Ghostscript.
1209 directory=(char *) NULL;
1210 if (LocaleCompare(name,"GS_DLL") == 0)
1212 directory=GetEnvironmentValue("MAGICK_GHOSTSCRIPT_PATH");
1213 if (directory != (char *) NULL)
1215 (void) FormatLocaleString(buffer,MagickPathExtent,"%s%sgsdll32.dll",
1216 directory,DirectorySeparator);
1217 if (IsPathAccessible(buffer) != MagickFalse)
1219 directory=DestroyString(directory);
1220 (void) CopyMagickString(value,buffer,length);
1221 if (is_64_bit != NULL)
1225 (void) FormatLocaleString(buffer,MagickPathExtent,"%s%sgsdll64.dll",
1226 directory,DirectorySeparator);
1227 if (IsPathAccessible(buffer) != MagickFalse)
1229 directory=DestroyString(directory);
1230 (void) CopyMagickString(value,buffer,length);
1231 if (is_64_bit != NULL)
1238 if (product_family == NULL)
1241 #if defined(KEY_WOW64_32KEY)
1243 flags=KEY_WOW64_64KEY;
1245 flags=KEY_WOW64_32KEY;
1247 (void) NTLocateGhostscript(flags,&root_index,&product_family,
1248 &major_version,&minor_version);
1249 if (product_family == NULL)
1251 flags=KEY_WOW64_32KEY;
1253 is_64_bit_version=TRUE;
1255 flags=KEY_WOW64_64KEY;
1259 if (product_family == NULL)
1261 (void) NTLocateGhostscript(flags,&root_index,&product_family,
1262 &major_version,&minor_version);
1263 #if !defined(_WIN64)
1264 is_64_bit_version=TRUE;
1267 if (product_family == NULL)
1269 if (is_64_bit != NULL)
1270 *is_64_bit=is_64_bit_version;
1271 (void) FormatLocaleString(buffer,MagickPathExtent,"SOFTWARE\\%s\\%d.%02d",
1272 product_family,major_version,minor_version);
1273 extent=(int) length;
1274 if (NTGetRegistryValue(registry_roots[root_index].hkey,buffer,flags,name,
1275 value,&extent) == 0)
1277 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1278 "registry: \"%s\\%s\\%s\"=\"%s\"",registry_roots[root_index].name,
1285 MagickPrivate int NTGhostscriptDLL(char *path,int length)
1288 dll[MagickPathExtent] = { "" };
1294 if ((*dll == '\0') &&
1295 (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,dll,sizeof(dll)) == FALSE))
1299 if (!is_64_bit_version)
1302 if (is_64_bit_version)
1305 (void) CopyMagickString(path,dll,length);
1310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1314 % N T G h o s t s c r i p t D L L V e c t o r s %
1318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1320 % NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
1321 % function vectors to invoke Ghostscript DLL functions. A null pointer is
1322 % returned if there is an error when loading the DLL or retrieving the
1325 % The format of the NTGhostscriptDLLVectors method is:
1327 % const GhostInfo *NTGhostscriptDLLVectors(void)
1330 MagickPrivate const GhostInfo *NTGhostscriptDLLVectors(void)
1332 if (NTGhostscriptLoadDLL() == FALSE)
1333 return((GhostInfo *) NULL);
1334 return(&ghost_info);
1338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1342 % N T G h o s t s c r i p t E X E %
1346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1348 % NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1349 % The method returns FALSE if a full path value is not obtained and returns
1350 % a default path of gswin32c.exe.
1352 % The format of the NTGhostscriptEXE method is:
1354 % int NTGhostscriptEXE(char *path,int length)
1356 % A description of each parameter follows:
1358 % o path: return the Ghostscript executable path here.
1360 % o length: length of buffer.
1363 MagickPrivate int NTGhostscriptEXE(char *path,int length)
1369 program[MagickPathExtent] = { "" };
1372 is_64_bit_version = FALSE;
1374 (void) CopyMagickString(path,"gswin32c.exe",length);
1375 if (*program == '\0')
1377 if (ghost_semaphore == (SemaphoreInfo *) NULL)
1378 ActivateSemaphoreInfo(&ghost_semaphore);
1379 LockSemaphoreInfo(ghost_semaphore);
1380 if (*program == '\0')
1382 if (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,program,
1383 sizeof(program)) == FALSE)
1385 UnlockSemaphoreInfo(ghost_semaphore);
1388 p=strrchr(program,'\\');
1389 if (p != (char *) NULL)
1393 (void) ConcatenateMagickString(program,is_64_bit_version ?
1394 "gswin64c.exe" : "gswin32c.exe",sizeof(program));
1397 UnlockSemaphoreInfo(ghost_semaphore);
1399 (void) CopyMagickString(path,program,length);
1404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1408 % N T G h o s t s c r i p t F o n t s %
1412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1414 % NTGhostscriptFonts() obtains the path to the Ghostscript fonts. The method
1415 % returns FALSE if it cannot determine the font path.
1417 % The format of the NTGhostscriptFonts method is:
1419 % int NTGhostscriptFonts(char *path, int length)
1421 % A description of each parameter follows:
1423 % o path: return the font path here.
1425 % o length: length of the path buffer.
1428 MagickPrivate int NTGhostscriptFonts(char *path,int length)
1431 buffer[MagickPathExtent],
1433 filename[MagickPathExtent];
1440 directory=GetEnvironmentValue("MAGICK_GHOSTSCRIPT_FONT_PATH");
1441 if (directory != (char *) NULL)
1443 (void) CopyMagickString(buffer,directory,MagickPathExtent);
1444 directory=DestroyString(directory);
1448 if (NTGhostscriptGetString("GS_LIB",NULL,buffer,MagickPathExtent) == FALSE)
1451 for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1453 (void) CopyMagickString(path,p+1,length+1);
1454 q=strchr(path,DirectoryListSeparator);
1455 if (q != (char *) NULL)
1457 (void) FormatLocaleString(filename,MagickPathExtent,"%s%sfonts.dir",path,
1458 DirectorySeparator);
1459 if (IsPathAccessible(filename) != MagickFalse)
1467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1471 % N T G h o s t s c r i p t L o a d D L L %
1475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1477 % NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1478 % TRUE if it succeeds.
1480 % The format of the NTGhostscriptLoadDLL method is:
1482 % int NTGhostscriptLoadDLL(void)
1485 static inline int NTGhostscriptHasValidHandle()
1487 if ((nt_ghost_info.delete_instance == NULL) || (ghost_info.exit == NULL) ||
1488 (ghost_info.init_with_args == NULL) ||
1489 (nt_ghost_info.new_instance == NULL) ||
1490 (ghost_info.run_string == NULL) || (ghost_info.set_stdio == NULL) ||
1491 (ghost_info.revision == NULL))
1498 MagickPrivate int NTGhostscriptLoadDLL(void)
1501 path[MagickPathExtent];
1503 if (ghost_semaphore == (SemaphoreInfo *) NULL)
1504 ActivateSemaphoreInfo(&ghost_semaphore);
1505 LockSemaphoreInfo(ghost_semaphore);
1506 if (ghost_handle != (void *) NULL)
1508 UnlockSemaphoreInfo(ghost_semaphore);
1509 return(NTGhostscriptHasValidHandle());
1511 if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
1513 UnlockSemaphoreInfo(ghost_semaphore);
1516 ghost_handle=lt_dlopen(path);
1517 if (ghost_handle == (void *) NULL)
1519 UnlockSemaphoreInfo(ghost_semaphore);
1522 (void) ResetMagickMemory((void *) &nt_ghost_info,0,sizeof(NTGhostInfo));
1523 nt_ghost_info.delete_instance=(void (MagickDLLCall *)(gs_main_instance *)) (
1524 lt_dlsym(ghost_handle,"gsapi_delete_instance"));
1525 nt_ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,
1526 void *)) (lt_dlsym(ghost_handle,"gsapi_new_instance"));
1527 nt_ghost_info.has_instance=MagickFalse;
1528 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1529 ghost_info.delete_instance=NTGhostscriptDeleteInstance;
1530 ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
1531 lt_dlsym(ghost_handle,"gsapi_exit");
1532 ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
1533 char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
1534 ghost_info.new_instance=NTGhostscriptNewInstance;
1535 ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
1536 int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
1537 ghost_info.set_stdio=(int (MagickDLLCall *)(gs_main_instance *,int(
1538 MagickDLLCall *)(void *,char *,int),int(MagickDLLCall *)(void *,
1539 const char *,int),int(MagickDLLCall *)(void *,const char *,int)))
1540 (lt_dlsym(ghost_handle,"gsapi_set_stdio"));
1541 ghost_info.revision=(int (MagickDLLCall *)(gsapi_revision_t *,int)) (
1542 lt_dlsym(ghost_handle,"gsapi_revision"));
1543 UnlockSemaphoreInfo(ghost_semaphore);
1544 return(NTGhostscriptHasValidHandle());
1548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1552 % N T G h o s t s c r i p t U n L o a d D L L %
1556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1558 % NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
1561 % The format of the NTGhostscriptUnLoadDLL method is:
1563 % int NTGhostscriptUnLoadDLL(void)
1566 MagickPrivate void NTGhostscriptUnLoadDLL(void)
1568 if (ghost_semaphore == (SemaphoreInfo *) NULL)
1569 ActivateSemaphoreInfo(&ghost_semaphore);
1570 LockSemaphoreInfo(ghost_semaphore);
1571 if (ghost_handle != (void *) NULL)
1573 (void) lt_dlclose(ghost_handle);
1574 ghost_handle=(void *) NULL;
1575 (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
1577 UnlockSemaphoreInfo(ghost_semaphore);
1578 RelinquishSemaphoreInfo(&ghost_semaphore);
1582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1586 % N T I n i t i a l i z e L i b r a r y %
1590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1592 % NTInitializeLibrary() initializes the dynamic module loading subsystem.
1594 % The format of the NTInitializeLibrary method is:
1596 % int NTInitializeLibrary(void)
1599 MagickPrivate int NTInitializeLibrary(void)
1605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1609 % N T I n i t i a l i z e W i n s o c k %
1613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1615 % NTInitializeWinsock() initializes Winsock.
1617 % The format of the NTInitializeWinsock method is:
1619 % void NTInitializeWinsock(void)
1622 MagickPrivate void NTInitializeWinsock(MagickBooleanType use_lock)
1626 if (winsock_semaphore == (SemaphoreInfo *) NULL)
1627 ActivateSemaphoreInfo(&winsock_semaphore);
1628 LockSemaphoreInfo(winsock_semaphore);
1630 if (wsaData == (WSADATA *) NULL)
1632 wsaData=(WSADATA *) AcquireMagickMemory(sizeof(WSADATA));
1633 if (WSAStartup(MAKEWORD(2,2),wsaData) != 0)
1634 ThrowFatalException(CacheFatalError,"WSAStartup failed");
1637 UnlockSemaphoreInfo(winsock_semaphore);
1641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1645 + N T M a p M e m o r y %
1649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1651 % Mmap() emulates the Unix method of the same name.
1653 % The format of the NTMapMemory method is:
1655 % MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1656 % int access,int file,MagickOffsetType offset)
1659 MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
1660 int flags,int file,MagickOffsetType offset)
1679 file_handle=INVALID_HANDLE_VALUE;
1680 low_length=(DWORD) (length & 0xFFFFFFFFUL);
1681 high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
1682 map_handle=INVALID_HANDLE_VALUE;
1684 low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
1685 high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
1687 if (protection & PROT_WRITE)
1689 access_mode=FILE_MAP_WRITE;
1690 if (!(flags & MAP_PRIVATE))
1691 protection_mode=PAGE_READWRITE;
1694 access_mode=FILE_MAP_COPY;
1695 protection_mode=PAGE_WRITECOPY;
1699 if (protection & PROT_READ)
1701 access_mode=FILE_MAP_READ;
1702 protection_mode=PAGE_READONLY;
1704 if ((file == -1) && (flags & MAP_ANONYMOUS))
1705 file_handle=INVALID_HANDLE_VALUE;
1707 file_handle=(HANDLE) _get_osfhandle(file);
1708 map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
1712 map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
1714 CloseHandle(map_handle);
1716 if (map == (void *) NULL)
1717 return((void *) ((char *) MAP_FAILED));
1718 return((void *) ((char *) map));
1722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1726 % N T O p e n D i r e c t o r y %
1730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1732 % NTOpenDirectory() opens the directory named by filename and associates a
1733 % directory stream with it.
1735 % The format of the NTOpenDirectory method is:
1737 % DIR *NTOpenDirectory(const char *path)
1739 % A description of each parameter follows:
1741 % o entry: Specifies a pointer to a DIR structure.
1744 MagickPrivate DIR *NTOpenDirectory(const char *path)
1753 file_specification[MagickPathExtent];
1755 assert(path != (const char *) NULL);
1756 length=MultiByteToWideChar(CP_UTF8,0,path,-1,file_specification,
1759 return((DIR *) NULL);
1760 if (wcsncat(file_specification,(const wchar_t*) DirectorySeparator,
1761 MagickPathExtent-wcslen(file_specification)-1) == (wchar_t*) NULL)
1762 return((DIR *) NULL);
1763 entry=(DIR *) AcquireMagickMemory(sizeof(DIR));
1764 if (entry != (DIR *) NULL)
1766 entry->firsttime=TRUE;
1767 entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
1769 if (entry->hSearch == INVALID_HANDLE_VALUE)
1771 if(wcsncat(file_specification,L"*.*",
1772 MagickPathExtent-wcslen(file_specification)-1) == (wchar_t*) NULL)
1774 entry=(DIR *) RelinquishMagickMemory(entry);
1775 return((DIR *) NULL);
1777 entry->hSearch=FindFirstFileW(file_specification,&entry->Win32FindData);
1778 if (entry->hSearch == INVALID_HANDLE_VALUE)
1780 entry=(DIR *) RelinquishMagickMemory(entry);
1781 return((DIR *) NULL);
1788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1792 % N T O p e n L i b r a r y %
1796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1798 % NTOpenLibrary() loads a dynamic module into memory and returns a handle that
1799 % can be used to access the various procedures in the module.
1801 % The format of the NTOpenLibrary method is:
1803 % void *NTOpenLibrary(const char *filename)
1805 % A description of each parameter follows:
1807 % o path: Specifies a pointer to string representing dynamic module that
1812 static inline const char *GetSearchPath(void)
1814 #if defined(MAGICKCORE_LTDL_DELEGATE)
1815 return(lt_dlgetsearchpath());
1817 return(lt_slsearchpath);
1821 static UINT ChangeErrorMode(void)
1824 (CALLBACK *GETERRORMODE)(void);
1835 mode=SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1837 handle=GetModuleHandle("kernel32.dll");
1838 if (handle == (HMODULE) NULL)
1839 return SetErrorMode(mode);
1841 getErrorMode=(GETERRORMODE) NTGetLibrarySymbol(handle,"GetErrorMode");
1842 if (getErrorMode != (GETERRORMODE) NULL)
1843 mode=getErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
1845 return SetErrorMode(mode);
1848 static inline void *NTLoadLibrary(const char *filename)
1854 path[MagickPathExtent];
1856 length=MultiByteToWideChar(CP_UTF8,0,filename,-1,path,MagickPathExtent);
1858 return((void *) NULL);
1859 return (void *) LoadLibraryExW(path,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
1862 MagickPrivate void *NTOpenLibrary(const char *filename)
1865 path[MagickPathExtent];
1877 mode=ChangeErrorMode();
1878 handle=NTLoadLibrary(filename);
1879 if (handle == (void *) NULL)
1882 while (p != (const char*) NULL)
1884 q=strchr(p,DirectoryListSeparator);
1885 if (q != (const char*) NULL)
1886 (void) CopyMagickString(path,p,q-p+1);
1888 (void) CopyMagickString(path,p,MagickPathExtent);
1889 (void) ConcatenateMagickString(path,DirectorySeparator,MagickPathExtent);
1890 (void) ConcatenateMagickString(path,filename,MagickPathExtent);
1891 handle=NTLoadLibrary(path);
1892 if (handle != (void *) NULL || q == (const char*) NULL)
1902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1906 % N T R e a d D i r e c t o r y %
1910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1912 % NTReadDirectory() returns a pointer to a structure representing the
1913 % directory entry at the current position in the directory stream to which
1916 % The format of the NTReadDirectory
1918 % NTReadDirectory(entry)
1920 % A description of each parameter follows:
1922 % o entry: Specifies a pointer to a DIR structure.
1925 MagickPrivate struct dirent *NTReadDirectory(DIR *entry)
1933 if (entry == (DIR *) NULL)
1934 return((struct dirent *) NULL);
1935 if (!entry->firsttime)
1937 status=FindNextFileW(entry->hSearch,&entry->Win32FindData);
1939 return((struct dirent *) NULL);
1941 length=WideCharToMultiByte(CP_UTF8,0,entry->Win32FindData.cFileName,-1,
1942 entry->file_info.d_name,sizeof(entry->file_info.d_name),NULL,NULL);
1944 return((struct dirent *) NULL);
1945 entry->firsttime=FALSE;
1946 entry->file_info.d_namlen=(int) strlen(entry->file_info.d_name);
1947 return(&entry->file_info);
1951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1955 % N T R e g i s t r y K e y L o o k u p %
1959 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1961 % NTRegistryKeyLookup() returns ImageMagick installation path settings
1962 % stored in the Windows Registry. Path settings are specific to the
1963 % installed ImageMagick version so that multiple Image Magick installations
1966 % Values are stored in the registry under a base path path similar to
1967 % "HKEY_LOCAL_MACHINE/SOFTWARE\ImageMagick\6.7.4\Q:16" or
1968 % "HKEY_CURRENT_USER/SOFTWARE\ImageMagick\6.7.4\Q:16". The provided subkey
1969 % is appended to this base path to form the full key.
1971 % The format of the NTRegistryKeyLookup method is:
1973 % unsigned char *NTRegistryKeyLookup(const char *subkey)
1975 % A description of each parameter follows:
1977 % o subkey: Specifies a string that identifies the registry object.
1978 % Currently supported sub-keys include: "BinPath", "ConfigurePath",
1979 % "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
1982 MagickPrivate unsigned char *NTRegistryKeyLookup(const char *subkey)
1985 package_key[MagickPathExtent];
2003 (void) FormatLocaleString(package_key,MagickPathExtent,"SOFTWARE\\%s\\%s\\Q:%d",
2004 MagickPackageName,MagickLibVersionText,MAGICKCORE_QUANTUM_DEPTH);
2005 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",package_key);
2006 registry_key=(HKEY) INVALID_HANDLE_VALUE;
2007 status=RegOpenKeyExA(HKEY_LOCAL_MACHINE,package_key,0,KEY_READ,®istry_key);
2008 if (status != ERROR_SUCCESS)
2009 status=RegOpenKeyExA(HKEY_CURRENT_USER,package_key,0,KEY_READ,
2011 if (status != ERROR_SUCCESS)
2013 registry_key=(HKEY) INVALID_HANDLE_VALUE;
2014 return((unsigned char *) NULL);
2020 value=(unsigned char *) AcquireQuantumMemory(size,sizeof(*value));
2021 if (value == (unsigned char *) NULL)
2023 RegCloseKey(registry_key);
2024 return((unsigned char *) NULL);
2026 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"%s",subkey);
2027 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2028 if ((status == ERROR_MORE_DATA) && (type == REG_SZ))
2030 value=(unsigned char *) ResizeQuantumMemory(value,size,sizeof(*value));
2031 if (value == (BYTE *) NULL)
2033 RegCloseKey(registry_key);
2034 return((unsigned char *) NULL);
2036 status=RegQueryValueExA(registry_key,subkey,0,&type,value,&size);
2038 RegCloseKey(registry_key);
2039 if ((type != REG_SZ) || (status != ERROR_SUCCESS))
2040 value=(unsigned char *) RelinquishMagickMemory(value);
2041 return((unsigned char *) value);
2045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2049 % N T R e p o r t E v e n t %
2053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2055 % NTReportEvent() reports an event.
2057 % The format of the NTReportEvent method is:
2059 % MagickBooleanType NTReportEvent(const char *event,
2060 % const MagickBooleanType error)
2062 % A description of each parameter follows:
2064 % o event: the event.
2066 % o error: MagickTrue the event is an error.
2069 MagickPrivate MagickBooleanType NTReportEvent(const char *event,
2070 const MagickBooleanType error)
2081 handle=RegisterEventSource(NULL,MAGICKCORE_PACKAGE_NAME);
2083 return(MagickFalse);
2085 type=error ? EVENTLOG_ERROR_TYPE : EVENTLOG_WARNING_TYPE;
2086 ReportEvent(handle,type,0,0,NULL,1,0,events,NULL);
2087 DeregisterEventSource(handle);
2092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2096 % N T R e s o u r c e T o B l o b %
2100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2102 % NTResourceToBlob() returns a blob containing the contents of the resource
2103 % in the current executable specified by the id parameter. This currently
2104 % used to retrieve MGK files tha have been embedded into the various command
2107 % The format of the NTResourceToBlob method is:
2109 % unsigned char *NTResourceToBlob(const char *id)
2111 % A description of each parameter follows:
2113 % o id: Specifies a string that identifies the resource.
2116 MagickPrivate unsigned char *NTResourceToBlob(const char *id)
2119 #ifndef MAGICKCORE_LIBRARY_NAME
2121 path[MagickPathExtent];
2140 assert(id != (const char *) NULL);
2141 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
2142 #ifdef MAGICKCORE_LIBRARY_NAME
2143 handle=GetModuleHandle(MAGICKCORE_LIBRARY_NAME);
2145 (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",GetClientPath(),
2146 DirectorySeparator,GetClientName());
2147 if (IsPathAccessible(path) != MagickFalse)
2148 handle=GetModuleHandle(path);
2150 handle=GetModuleHandle(0);
2153 return((unsigned char *) NULL);
2154 resource=FindResource(handle,id,"IMAGEMAGICK");
2156 return((unsigned char *) NULL);
2157 global=LoadResource(handle,resource);
2159 return((unsigned char *) NULL);
2160 length=SizeofResource(handle,resource);
2161 value=(unsigned char *) LockResource(global);
2164 FreeResource(global);
2165 return((unsigned char *) NULL);
2167 blob=(unsigned char *) AcquireQuantumMemory(length+MagickPathExtent,
2169 if (blob != (unsigned char *) NULL)
2171 (void) CopyMagickMemory(blob,value,length);
2174 UnlockResource(global);
2175 FreeResource(global);
2180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2184 % N T S e e k D i r e c t o r y %
2188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2190 % NTSeekDirectory() sets the position of the next NTReadDirectory() operation
2191 % on the directory stream.
2193 % The format of the NTSeekDirectory method is:
2195 % void NTSeekDirectory(DIR *entry,ssize_t position)
2197 % A description of each parameter follows:
2199 % o entry: Specifies a pointer to a DIR structure.
2201 % o position: specifies the position associated with the directory
2205 MagickPrivate void NTSeekDirectory(DIR *entry,ssize_t position)
2208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2209 assert(entry != (DIR *) NULL);
2213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2217 % N T S e t S e a r c h P a t h %
2221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2223 % NTSetSearchPath() sets the current locations that the subsystem should
2224 % look at to find dynamically loadable modules.
2226 % The format of the NTSetSearchPath method is:
2228 % int NTSetSearchPath(const char *path)
2230 % A description of each parameter follows:
2232 % o path: Specifies a pointer to string representing the search path
2233 % for DLL's that can be dynamically loaded.
2236 MagickPrivate int NTSetSearchPath(const char *path)
2238 #if defined(MAGICKCORE_LTDL_DELEGATE)
2239 lt_dlsetsearchpath(path);
2241 if (lt_slsearchpath != (char *) NULL)
2242 lt_slsearchpath=DestroyString(lt_slsearchpath);
2243 if (path != (char *) NULL)
2244 lt_slsearchpath=AcquireString(path);
2250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2254 + N T S y n c M e m o r y %
2258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2260 % NTSyncMemory() emulates the Unix method of the same name.
2262 % The format of the NTSyncMemory method is:
2264 % int NTSyncMemory(void *address,size_t length,int flags)
2266 % A description of each parameter follows:
2268 % o address: the address of the binary large object.
2270 % o length: the length of the binary large object.
2272 % o flags: Option flags (ignored for Windows).
2275 MagickPrivate int NTSyncMemory(void *address,size_t length,int flags)
2278 if (FlushViewOfFile(address,length) == MagickFalse)
2284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2288 % N T S y s t e m C o m m a n d %
2292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2294 % NTSystemCommand() executes the specified command and waits until it
2295 % terminates. The returned value is the exit status of the command.
2297 % The format of the NTSystemCommand method is:
2299 % int NTSystemCommand(MagickFalse,const char *command)
2301 % A description of each parameter follows:
2303 % o command: This string is the command to execute.
2305 % o output: an optional buffer to store the output from stderr/stdout.
2308 MagickPrivate int NTSystemCommand(const char *command,char *output)
2310 #define CleanupOutputHandles \
2311 if (read_output != (HANDLE) NULL) \
2313 CloseHandle(read_output); \
2314 read_output=(HANDLE) NULL; \
2315 CloseHandle(write_output); \
2316 write_output=(HANDLE) NULL; \
2319 #define CopyLastError \
2320 if (output != (char *) NULL) \
2322 error=NTGetLastError(); \
2323 if (error != (char *) NULL) \
2325 CopyMagickString(output,error,MagickPathExtent); \
2326 error=DestroyString(error); \
2332 local_command[MagickPathExtent];
2358 if (command == (char *) NULL)
2360 read_output=(HANDLE) NULL;
2361 write_output=(HANDLE) NULL;
2362 GetStartupInfo(&startup_info);
2363 startup_info.dwFlags=STARTF_USESHOWWINDOW;
2364 startup_info.wShowWindow=SW_SHOWMINNOACTIVE;
2365 (void) CopyMagickString(local_command,command,MagickPathExtent);
2366 asynchronous=command[strlen(command)-1] == '&' ? MagickTrue : MagickFalse;
2367 if (asynchronous != MagickFalse)
2369 local_command[strlen(command)-1]='\0';
2370 startup_info.wShowWindow=SW_SHOWDEFAULT;
2374 if (command[strlen(command)-1] == '|')
2375 local_command[strlen(command)-1]='\0';
2377 startup_info.wShowWindow=SW_HIDE;
2378 read_output=(HANDLE) NULL;
2379 if (output != (char *) NULL)
2381 sa.nLength=sizeof(SECURITY_ATTRIBUTES);
2382 sa.bInheritHandle=TRUE;
2383 sa.lpSecurityDescriptor=NULL;
2384 if (CreatePipe(&read_output,&write_output,NULL,0))
2386 if (SetHandleInformation(write_output,HANDLE_FLAG_INHERIT,
2387 HANDLE_FLAG_INHERIT))
2389 startup_info.dwFlags|=STARTF_USESTDHANDLES;
2390 startup_info.hStdOutput=write_output;
2391 startup_info.hStdError=write_output;
2394 CleanupOutputHandles;
2397 read_output=(HANDLE) NULL;
2400 status=CreateProcess((LPCTSTR) NULL,local_command,(LPSECURITY_ATTRIBUTES)
2401 NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) TRUE,(DWORD)
2402 NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
2407 CleanupOutputHandles;
2410 if (asynchronous != MagickFalse)
2411 return(status == 0);
2412 status=WaitForSingleObject(process_info.hProcess,INFINITE);
2413 if (status != WAIT_OBJECT_0)
2416 CleanupOutputHandles;
2419 status=GetExitCodeProcess(process_info.hProcess,&child_status);
2423 CleanupOutputHandles;
2426 CloseHandle(process_info.hProcess);
2427 CloseHandle(process_info.hThread);
2428 if (read_output != (HANDLE) NULL)
2429 if (PeekNamedPipe(read_output,(LPVOID) NULL,0,(LPDWORD) NULL,&size,
2431 if ((size > 0) && (ReadFile(read_output,output,MagickPathExtent-1,
2433 output[bytes_read]='\0';
2434 CleanupOutputHandles;
2435 return((int) child_status);
2439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2443 % N T S y s t e m C o n i f i g u r a t i o n %
2447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2449 % NTSystemConfiguration() provides a way for the application to determine
2450 % values for system limits or options at runtime.
2452 % The format of the exit method is:
2454 % ssize_t NTSystemConfiguration(int name)
2456 % A description of each parameter follows:
2458 % o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
2461 MagickPrivate ssize_t NTSystemConfiguration(int name)
2470 GetSystemInfo(&system_info);
2471 return(system_info.dwPageSize);
2473 case _SC_PHYS_PAGES:
2487 handle=GetModuleHandle("kernel32.dll");
2488 if (handle == (HMODULE) NULL)
2490 GetSystemInfo(&system_info);
2491 module=(LPFNDLLFUNC2) NTGetLibrarySymbol(handle,"GlobalMemoryStatusEx");
2492 if (module == (LPFNDLLFUNC2) NULL)
2497 GlobalMemoryStatus(&global_status);
2498 return((ssize_t) global_status.dwTotalPhys/system_info.dwPageSize/4);
2500 status.dwLength=sizeof(status);
2501 if (module(&status) == 0)
2503 return((ssize_t) status.ullTotalPhys/system_info.dwPageSize/4);
2514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2518 % N T T e l l D i r e c t o r y %
2522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2524 % NTTellDirectory() returns the current location associated with the named
2527 % The format of the NTTellDirectory method is:
2529 % ssize_t NTTellDirectory(DIR *entry)
2531 % A description of each parameter follows:
2533 % o entry: Specifies a pointer to a DIR structure.
2536 MagickPrivate ssize_t NTTellDirectory(DIR *entry)
2538 assert(entry != (DIR *) NULL);
2543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2547 % N T T r u n c a t e F i l e %
2551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2553 % NTTruncateFile() truncates a file to a specified length.
2555 % The format of the NTTruncateFile method is:
2557 % int NTTruncateFile(int file,off_t length)
2559 % A description of each parameter follows:
2563 % o length: the file length.
2566 MagickPrivate int NTTruncateFile(int file,off_t length)
2578 file_handle=(HANDLE) _get_osfhandle(file);
2579 if (file_handle == INVALID_HANDLE_VALUE)
2581 low=(long) (length & 0xffffffffUL);
2582 high=(long) ((((MagickOffsetType) length) >> 32) & 0xffffffffUL);
2583 file_pointer=SetFilePointer(file_handle,low,&high,FILE_BEGIN);
2584 if ((file_pointer == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
2586 if (SetEndOfFile(file_handle) == 0)
2592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2596 + N T U n m a p M e m o r y %
2600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2602 % NTUnmapMemory() emulates the Unix munmap method.
2604 % The format of the NTUnmapMemory method is:
2606 % int NTUnmapMemory(void *map,size_t length)
2608 % A description of each parameter follows:
2610 % o map: the address of the binary large object.
2612 % o length: the length of the binary large object.
2615 MagickPrivate int NTUnmapMemory(void *map,size_t length)
2618 if (UnmapViewOfFile(map) == 0)
2624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2628 % N T U s e r T i m e %
2632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2634 % NTUserTime() returns the total time the process has been scheduled (e.g.
2635 % seconds) since the last call to StartTimer().
2637 % The format of the UserTime method is:
2639 % double NTUserTime(void)
2642 MagickPrivate double NTUserTime(void)
2672 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
2673 GetVersionEx(&OsVersionInfo);
2674 if (OsVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
2675 return(NTElapsedTime());
2676 status=GetProcessTimes(GetCurrentProcess(),&create_time,&exit_time,
2677 &kernel_time.filetime,&user_time.filetime);
2680 return((double) 1.0e-7*(kernel_time.filetime64+user_time.filetime64));
2684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2688 % N T W a r n i n g H a n d l e r %
2692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2694 % NTWarningHandler() displays a warning reason.
2696 % The format of the NTWarningHandler method is:
2698 % void NTWarningHandler(const ExceptionType severity,const char *reason,
2699 % const char *description)
2701 % A description of each parameter follows:
2703 % o severity: Specifies the numeric warning category.
2705 % o reason: Specifies the reason to display before terminating the
2708 % o description: Specifies any description to the reason.
2711 MagickPrivate void NTWarningHandler(const ExceptionType severity,
2712 const char *reason,const char *description)
2715 buffer[2*MagickPathExtent];
2718 if (reason == (char *) NULL)
2720 if (description == (char *) NULL)
2721 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s.\n",GetClientName(),
2724 (void) FormatLocaleString(buffer,MagickPathExtent,"%s: %s (%s).\n",
2725 GetClientName(),reason,description);
2726 (void) MessageBox(NULL,buffer,"ImageMagick Warning",MB_OK | MB_TASKMODAL |
2727 MB_SETFOREGROUND | MB_ICONINFORMATION);
2731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2735 % N T W i n d o w s G e n e s i s %
2739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2741 % NTWindowsGenesis() initializes the MagickCore Windows environment.
2743 % The format of the NTWindowsGenesis method is:
2745 % void NTWindowsGenesis(void)
2749 static LONG WINAPI NTUncaughtException(EXCEPTION_POINTERS *info)
2751 magick_unreferenced(info);
2752 AsynchronousResourceComponentTerminus();
2753 return(EXCEPTION_CONTINUE_SEARCH);
2756 MagickPrivate void NTWindowsGenesis(void)
2761 SetUnhandledExceptionFilter(NTUncaughtException);
2762 mode=GetEnvironmentValue("MAGICK_ERRORMODE");
2763 if (mode != (char *) NULL)
2765 (void) SetErrorMode(StringToInteger(mode));
2766 mode=DestroyString(mode);
2768 #if defined(_DEBUG) && !defined(__BORLANDC__) && !defined(__MINGW32__) && !defined(__MINGW64__)
2769 if (IsEventLogging() != MagickFalse)
2774 debug=_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
2775 debug|=_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF |
2776 _CRTDBG_LEAK_CHECK_DF;
2777 (void) _CrtSetDbgFlag(debug);
2778 _ASSERTE(_CrtCheckMemory());
2784 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2788 % N T W i n d o w s T e r m i n u s %
2792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2794 % NTWindowsTerminus() terminates the MagickCore Windows environment.
2796 % The format of the NTWindowsTerminus method is:
2798 % void NTWindowsTerminus(void)
2801 MagickPrivate void NTWindowsTerminus(void)
2803 NTGhostscriptUnLoadDLL();
2804 if (winsock_semaphore == (SemaphoreInfo *) NULL)
2805 ActivateSemaphoreInfo(&winsock_semaphore);
2806 LockSemaphoreInfo(winsock_semaphore);
2807 if (wsaData != (WSADATA *) NULL)
2810 wsaData=(WSADATA *) RelinquishMagickMemory((void *) wsaData);
2812 UnlockSemaphoreInfo(winsock_semaphore);
2813 RelinquishSemaphoreInfo(&winsock_semaphore);